2 * Copyright 2008 Ben Skeggs
3 * Copyright 2010 Christoph Bumiller
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
24 #include "pipe/p_context.h"
25 #include "pipe/p_defines.h"
26 #include "pipe/p_state.h"
27 #include "util/u_inlines.h"
29 #include "nv50/nv50_context.h"
32 nv50_constbufs_validate(struct nv50_context
*nv50
)
34 struct nouveau_pushbuf
*push
= nv50
->base
.pushbuf
;
37 for (s
= 0; s
< 3; ++s
) {
40 if (s
== PIPE_SHADER_FRAGMENT
)
41 p
= NV50_3D_SET_PROGRAM_CB_PROGRAM_FRAGMENT
;
43 if (s
== PIPE_SHADER_GEOMETRY
)
44 p
= NV50_3D_SET_PROGRAM_CB_PROGRAM_GEOMETRY
;
46 p
= NV50_3D_SET_PROGRAM_CB_PROGRAM_VERTEX
;
48 while (nv50
->constbuf_dirty
[s
]) {
49 const unsigned i
= (unsigned)ffs(nv50
->constbuf_dirty
[s
]) - 1;
51 assert(i
< NV50_MAX_PIPE_CONSTBUFS
);
52 nv50
->constbuf_dirty
[s
] &= ~(1 << i
);
54 if (nv50
->constbuf
[s
][i
].user
) {
55 const unsigned b
= NV50_CB_PVP
+ s
;
57 unsigned words
= nv50
->constbuf
[s
][0].size
/ 4;
59 NOUVEAU_ERR("user constbufs only supported in slot 0\n");
62 if (!nv50
->state
.uniform_buffer_bound
[s
]) {
63 nv50
->state
.uniform_buffer_bound
[s
] = true;
64 BEGIN_NV04(push
, NV50_3D(SET_PROGRAM_CB
), 1);
65 PUSH_DATA (push
, (b
<< 12) | (i
<< 8) | p
| 1);
68 unsigned nr
= MIN2(words
, NV04_PFIFO_MAX_PACKET_LEN
);
70 PUSH_SPACE(push
, nr
+ 3);
71 BEGIN_NV04(push
, NV50_3D(CB_ADDR
), 1);
72 PUSH_DATA (push
, (start
<< 8) | b
);
73 BEGIN_NI04(push
, NV50_3D(CB_DATA(0)), nr
);
74 PUSH_DATAp(push
, &nv50
->constbuf
[s
][0].u
.data
[start
* 4], nr
);
80 struct nv04_resource
*res
=
81 nv04_resource(nv50
->constbuf
[s
][i
].u
.buf
);
83 /* TODO: allocate persistent bindings */
84 const unsigned b
= s
* 16 + i
;
86 assert(nouveau_resource_mapped_by_gpu(&res
->base
));
88 BEGIN_NV04(push
, NV50_3D(CB_DEF_ADDRESS_HIGH
), 3);
89 PUSH_DATAh(push
, res
->address
+ nv50
->constbuf
[s
][i
].offset
);
90 PUSH_DATA (push
, res
->address
+ nv50
->constbuf
[s
][i
].offset
);
91 PUSH_DATA (push
, (b
<< 16) |
92 (nv50
->constbuf
[s
][i
].size
& 0xffff));
93 BEGIN_NV04(push
, NV50_3D(SET_PROGRAM_CB
), 1);
94 PUSH_DATA (push
, (b
<< 12) | (i
<< 8) | p
| 1);
96 BCTX_REFN(nv50
->bufctx_3d
, CB(s
, i
), res
, RD
);
98 nv50
->cb_dirty
= 1; /* Force cache flush for UBO. */
100 BEGIN_NV04(push
, NV50_3D(SET_PROGRAM_CB
), 1);
101 PUSH_DATA (push
, (i
<< 8) | p
| 0);
104 nv50
->state
.uniform_buffer_bound
[s
] = false;
111 nv50_program_validate(struct nv50_context
*nv50
, struct nv50_program
*prog
)
113 if (!prog
->translated
) {
114 prog
->translated
= nv50_program_translate(
115 prog
, nv50
->screen
->base
.device
->chipset
);
116 if (!prog
->translated
)
122 return nv50_program_upload_code(nv50
, prog
);
126 nv50_program_update_context_state(struct nv50_context
*nv50
,
127 struct nv50_program
*prog
, int stage
)
129 const unsigned flags
= NOUVEAU_BO_VRAM
| NOUVEAU_BO_RDWR
;
131 if (prog
&& prog
->tls_space
) {
132 if (nv50
->state
.new_tls_space
)
133 nouveau_bufctx_reset(nv50
->bufctx_3d
, NV50_BIND_TLS
);
134 if (!nv50
->state
.tls_required
|| nv50
->state
.new_tls_space
)
135 BCTX_REFN_bo(nv50
->bufctx_3d
, TLS
, flags
, nv50
->screen
->tls_bo
);
136 nv50
->state
.new_tls_space
= false;
137 nv50
->state
.tls_required
|= 1 << stage
;
139 if (nv50
->state
.tls_required
== (1 << stage
))
140 nouveau_bufctx_reset(nv50
->bufctx_3d
, NV50_BIND_TLS
);
141 nv50
->state
.tls_required
&= ~(1 << stage
);
146 nv50_vertprog_validate(struct nv50_context
*nv50
)
148 struct nouveau_pushbuf
*push
= nv50
->base
.pushbuf
;
149 struct nv50_program
*vp
= nv50
->vertprog
;
151 if (!nv50_program_validate(nv50
, vp
))
153 nv50_program_update_context_state(nv50
, vp
, 0);
155 BEGIN_NV04(push
, NV50_3D(VP_ATTR_EN(0)), 2);
156 PUSH_DATA (push
, vp
->vp
.attrs
[0]);
157 PUSH_DATA (push
, vp
->vp
.attrs
[1]);
158 BEGIN_NV04(push
, NV50_3D(VP_REG_ALLOC_RESULT
), 1);
159 PUSH_DATA (push
, vp
->max_out
);
160 BEGIN_NV04(push
, NV50_3D(VP_REG_ALLOC_TEMP
), 1);
161 PUSH_DATA (push
, vp
->max_gpr
);
162 BEGIN_NV04(push
, NV50_3D(VP_START_ID
), 1);
163 PUSH_DATA (push
, vp
->code_base
);
167 nv50_fragprog_validate(struct nv50_context
*nv50
)
169 struct nouveau_pushbuf
*push
= nv50
->base
.pushbuf
;
170 struct nv50_program
*fp
= nv50
->fragprog
;
171 struct pipe_rasterizer_state
*rast
= &nv50
->rast
->pipe
;
173 if (fp
->fp
.force_persample_interp
!= rast
->force_persample_interp
) {
174 /* Force the program to be reuploaded, which will trigger interp fixups
178 nouveau_heap_free(&fp
->mem
);
180 fp
->fp
.force_persample_interp
= rast
->force_persample_interp
;
183 if (fp
->mem
&& !(nv50
->dirty
& (NV50_NEW_FRAGPROG
| NV50_NEW_MIN_SAMPLES
)))
186 if (!nv50_program_validate(nv50
, fp
))
188 nv50_program_update_context_state(nv50
, fp
, 1);
190 BEGIN_NV04(push
, NV50_3D(FP_REG_ALLOC_TEMP
), 1);
191 PUSH_DATA (push
, fp
->max_gpr
);
192 BEGIN_NV04(push
, NV50_3D(FP_RESULT_COUNT
), 1);
193 PUSH_DATA (push
, fp
->max_out
);
194 BEGIN_NV04(push
, NV50_3D(FP_CONTROL
), 1);
195 PUSH_DATA (push
, fp
->fp
.flags
[0]);
196 BEGIN_NV04(push
, NV50_3D(FP_CTRL_UNK196C
), 1);
197 PUSH_DATA (push
, fp
->fp
.flags
[1]);
198 BEGIN_NV04(push
, NV50_3D(FP_START_ID
), 1);
199 PUSH_DATA (push
, fp
->code_base
);
201 if (nv50
->screen
->tesla
->oclass
>= NVA3_3D_CLASS
) {
202 BEGIN_NV04(push
, SUBC_3D(NVA3_3D_FP_MULTISAMPLE
), 1);
203 if (nv50
->min_samples
> 1 || fp
->fp
.has_samplemask
)
205 NVA3_3D_FP_MULTISAMPLE_FORCE_PER_SAMPLE
|
206 (NVA3_3D_FP_MULTISAMPLE_EXPORT_SAMPLE_MASK
*
207 fp
->fp
.has_samplemask
));
214 nv50_gmtyprog_validate(struct nv50_context
*nv50
)
216 struct nouveau_pushbuf
*push
= nv50
->base
.pushbuf
;
217 struct nv50_program
*gp
= nv50
->gmtyprog
;
220 if (!nv50_program_validate(nv50
, gp
))
222 BEGIN_NV04(push
, NV50_3D(GP_REG_ALLOC_TEMP
), 1);
223 PUSH_DATA (push
, gp
->max_gpr
);
224 BEGIN_NV04(push
, NV50_3D(GP_REG_ALLOC_RESULT
), 1);
225 PUSH_DATA (push
, gp
->max_out
);
226 BEGIN_NV04(push
, NV50_3D(GP_OUTPUT_PRIMITIVE_TYPE
), 1);
227 PUSH_DATA (push
, gp
->gp
.prim_type
);
228 BEGIN_NV04(push
, NV50_3D(GP_VERTEX_OUTPUT_COUNT
), 1);
229 PUSH_DATA (push
, gp
->gp
.vert_count
);
230 BEGIN_NV04(push
, NV50_3D(GP_START_ID
), 1);
231 PUSH_DATA (push
, gp
->code_base
);
233 nv50
->state
.prim_size
= gp
->gp
.prim_type
; /* enum matches vertex count */
235 nv50_program_update_context_state(nv50
, gp
, 2);
237 /* GP_ENABLE is updated in linkage validation */
241 nv50_sprite_coords_validate(struct nv50_context
*nv50
)
243 struct nouveau_pushbuf
*push
= nv50
->base
.pushbuf
;
244 uint32_t pntc
[8], mode
;
245 struct nv50_program
*fp
= nv50
->fragprog
;
247 unsigned m
= (nv50
->state
.interpolant_ctrl
>> 8) & 0xff;
249 if (!nv50
->rast
->pipe
.point_quad_rasterization
) {
250 if (nv50
->state
.point_sprite
) {
251 BEGIN_NV04(push
, NV50_3D(POINT_COORD_REPLACE_MAP(0)), 8);
252 for (i
= 0; i
< 8; ++i
)
255 nv50
->state
.point_sprite
= false;
259 nv50
->state
.point_sprite
= true;
262 memset(pntc
, 0, sizeof(pntc
));
264 for (i
= 0; i
< fp
->in_nr
; i
++) {
265 unsigned n
= util_bitcount(fp
->in
[i
].mask
);
267 if (fp
->in
[i
].sn
!= TGSI_SEMANTIC_GENERIC
) {
271 if (!(nv50
->rast
->pipe
.sprite_coord_enable
& (1 << fp
->in
[i
].si
))) {
276 for (c
= 0; c
< 4; ++c
) {
277 if (fp
->in
[i
].mask
& (1 << c
)) {
278 pntc
[m
/ 8] |= (c
+ 1) << ((m
% 8) * 4);
284 if (nv50
->rast
->pipe
.sprite_coord_mode
== PIPE_SPRITE_COORD_LOWER_LEFT
)
289 BEGIN_NV04(push
, NV50_3D(POINT_SPRITE_CTRL
), 1);
290 PUSH_DATA (push
, mode
);
292 BEGIN_NV04(push
, NV50_3D(POINT_COORD_REPLACE_MAP(0)), 8);
293 PUSH_DATAp(push
, pntc
, 8);
296 /* Validate state derived from shaders and the rasterizer cso. */
298 nv50_validate_derived_rs(struct nv50_context
*nv50
)
300 struct nouveau_pushbuf
*push
= nv50
->base
.pushbuf
;
301 uint32_t color
, psize
;
303 nv50_sprite_coords_validate(nv50
);
305 if (nv50
->state
.rasterizer_discard
!= nv50
->rast
->pipe
.rasterizer_discard
) {
306 nv50
->state
.rasterizer_discard
= nv50
->rast
->pipe
.rasterizer_discard
;
307 BEGIN_NV04(push
, NV50_3D(RASTERIZE_ENABLE
), 1);
308 PUSH_DATA (push
, !nv50
->rast
->pipe
.rasterizer_discard
);
311 if (nv50
->dirty
& NV50_NEW_FRAGPROG
)
313 psize
= nv50
->state
.semantic_psize
& ~NV50_3D_SEMANTIC_PTSZ_PTSZ_EN__MASK
;
314 color
= nv50
->state
.semantic_color
& ~NV50_3D_SEMANTIC_COLOR_CLMP_EN
;
316 if (nv50
->rast
->pipe
.clamp_vertex_color
)
317 color
|= NV50_3D_SEMANTIC_COLOR_CLMP_EN
;
319 if (color
!= nv50
->state
.semantic_color
) {
320 nv50
->state
.semantic_color
= color
;
321 BEGIN_NV04(push
, NV50_3D(SEMANTIC_COLOR
), 1);
322 PUSH_DATA (push
, color
);
325 if (nv50
->rast
->pipe
.point_size_per_vertex
)
326 psize
|= NV50_3D_SEMANTIC_PTSZ_PTSZ_EN__MASK
;
328 if (psize
!= nv50
->state
.semantic_psize
) {
329 nv50
->state
.semantic_psize
= psize
;
330 BEGIN_NV04(push
, NV50_3D(SEMANTIC_PTSZ
), 1);
331 PUSH_DATA (push
, psize
);
336 nv50_vec4_map(uint8_t *map
, int mid
, uint32_t lin
[4],
337 struct nv50_varying
*in
, struct nv50_varying
*out
)
340 uint8_t mv
= out
->mask
, mf
= in
->mask
, oid
= out
->hw
;
342 for (c
= 0; c
< 4; ++c
) {
345 lin
[mid
/ 32] |= 1 << (mid
% 32);
363 nv50_fp_linkage_validate(struct nv50_context
*nv50
)
365 struct nouveau_pushbuf
*push
= nv50
->base
.pushbuf
;
366 struct nv50_program
*vp
= nv50
->gmtyprog
? nv50
->gmtyprog
: nv50
->vertprog
;
367 struct nv50_program
*fp
= nv50
->fragprog
;
368 struct nv50_varying dummy
;
371 uint32_t layerid
= 0;
372 uint32_t viewportid
= 0;
373 uint32_t psiz
= 0x000;
374 uint32_t interp
= fp
->fp
.interp
;
375 uint32_t colors
= fp
->fp
.colors
;
380 if (!(nv50
->dirty
& (NV50_NEW_VERTPROG
|
382 NV50_NEW_GMTYPROG
))) {
384 ffc
= (nv50
->state
.semantic_color
& NV50_3D_SEMANTIC_COLOR_FFC0_ID__MASK
);
385 bfc
= (nv50
->state
.semantic_color
& NV50_3D_SEMANTIC_COLOR_BFC0_ID__MASK
)
387 if (nv50
->rast
->pipe
.light_twoside
== ((ffc
== bfc
) ? 0 : 1))
391 memset(lin
, 0x00, sizeof(lin
));
393 /* XXX: in buggy-endian mode, is the first element of map (u32)0x000000xx
394 * or is it the first byte ?
396 memset(map
, nv50
->gmtyprog
? 0x80 : 0x40, sizeof(map
));
398 dummy
.mask
= 0xf; /* map all components of HPOS */
400 m
= nv50_vec4_map(map
, 0, lin
, &dummy
, &vp
->out
[0]);
402 for (c
= 0; c
< vp
->vp
.clpd_nr
; ++c
)
403 map
[m
++] = vp
->vp
.clpd
[c
/ 4] + (c
% 4);
405 colors
|= m
<< 8; /* adjust BFC0 id */
409 /* if light_twoside is active, FFC0_ID == BFC0_ID is invalid */
410 if (nv50
->rast
->pipe
.light_twoside
) {
411 for (i
= 0; i
< 2; ++i
) {
413 if (fp
->vp
.bfc
[i
] >= fp
->in_nr
)
415 m
= nv50_vec4_map(map
, m
, lin
, &fp
->in
[fp
->vp
.bfc
[i
]],
416 (n
< vp
->out_nr
) ? &vp
->out
[n
] : &dummy
);
419 colors
+= m
- 4; /* adjust FFC0 id */
420 interp
|= m
<< 8; /* set map id where 'normal' FP inputs start */
422 for (i
= 0; i
< fp
->in_nr
; ++i
) {
423 for (n
= 0; n
< vp
->out_nr
; ++n
)
424 if (vp
->out
[n
].sn
== fp
->in
[i
].sn
&&
425 vp
->out
[n
].si
== fp
->in
[i
].si
)
427 switch (fp
->in
[i
].sn
) {
428 case TGSI_SEMANTIC_PRIMID
:
431 case TGSI_SEMANTIC_LAYER
:
434 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
438 m
= nv50_vec4_map(map
, m
, lin
,
439 &fp
->in
[i
], (n
< vp
->out_nr
) ? &vp
->out
[n
] : &dummy
);
442 if (vp
->gp
.has_layer
&& !layerid
) {
444 map
[m
++] = vp
->gp
.layerid
;
447 if (vp
->gp
.has_viewport
&& !viewportid
) {
449 map
[m
++] = vp
->gp
.viewportid
;
452 if (nv50
->rast
->pipe
.point_size_per_vertex
) {
454 map
[m
++] = vp
->vp
.psiz
;
457 if (nv50
->rast
->pipe
.clamp_vertex_color
)
458 colors
|= NV50_3D_SEMANTIC_COLOR_CLMP_EN
;
460 if (unlikely(vp
->so
)) {
461 /* Slot i in STRMOUT_MAP specifies the offset where slot i in RESULT_MAP
465 * Inverting vp->so->map (output -> offset) would probably speed this up.
467 memset(so_map
, 0, sizeof(so_map
));
468 for (i
= 0; i
< vp
->so
->map_size
; ++i
) {
469 if (vp
->so
->map
[i
] == 0xff)
471 for (c
= 0; c
< m
; ++c
)
472 if (map
[c
] == vp
->so
->map
[i
] && !so_map
[c
])
476 map
[m
++] = vp
->so
->map
[i
];
478 so_map
[c
] = 0x80 | i
;
480 for (c
= m
; c
& 3; ++c
)
487 if (unlikely(nv50
->gmtyprog
)) {
488 BEGIN_NV04(push
, NV50_3D(GP_RESULT_MAP_SIZE
), 1);
490 BEGIN_NV04(push
, NV50_3D(GP_RESULT_MAP(0)), n
);
491 PUSH_DATAp(push
, map
, n
);
493 BEGIN_NV04(push
, NV50_3D(VP_GP_BUILTIN_ATTR_EN
), 1);
494 PUSH_DATA (push
, vp
->vp
.attrs
[2] | fp
->vp
.attrs
[2]);
496 BEGIN_NV04(push
, NV50_3D(SEMANTIC_PRIM_ID
), 1);
497 PUSH_DATA (push
, primid
);
500 BEGIN_NV04(push
, NV50_3D(VP_RESULT_MAP_SIZE
), 1);
502 BEGIN_NV04(push
, NV50_3D(VP_RESULT_MAP(0)), n
);
503 PUSH_DATAp(push
, map
, n
);
506 BEGIN_NV04(push
, NV50_3D(GP_VIEWPORT_ID_ENABLE
), 5);
507 PUSH_DATA (push
, vp
->gp
.has_viewport
);
508 PUSH_DATA (push
, colors
);
509 PUSH_DATA (push
, (vp
->vp
.clpd_nr
<< 8) | 4);
510 PUSH_DATA (push
, layerid
);
511 PUSH_DATA (push
, psiz
);
513 BEGIN_NV04(push
, NV50_3D(SEMANTIC_VIEWPORT
), 1);
514 PUSH_DATA (push
, viewportid
);
516 BEGIN_NV04(push
, NV50_3D(LAYER
), 1);
517 PUSH_DATA (push
, vp
->gp
.has_layer
<< 16);
519 BEGIN_NV04(push
, NV50_3D(FP_INTERPOLANT_CTRL
), 1);
520 PUSH_DATA (push
, interp
);
522 nv50
->state
.interpolant_ctrl
= interp
;
524 nv50
->state
.semantic_color
= colors
;
525 nv50
->state
.semantic_psize
= psiz
;
527 BEGIN_NV04(push
, NV50_3D(NOPERSPECTIVE_BITMAP(0)), 4);
528 PUSH_DATAp(push
, lin
, 4);
530 BEGIN_NV04(push
, NV50_3D(GP_ENABLE
), 1);
531 PUSH_DATA (push
, nv50
->gmtyprog
? 1 : 0);
534 BEGIN_NV04(push
, NV50_3D(STRMOUT_MAP(0)), n
);
535 PUSH_DATAp(push
, so_map
, n
);
540 nv50_vp_gp_mapping(uint8_t *map
, int m
,
541 struct nv50_program
*vp
, struct nv50_program
*gp
)
545 for (i
= 0; i
< gp
->in_nr
; ++i
) {
546 uint8_t oid
= 0, mv
= 0, mg
= gp
->in
[i
].mask
;
548 for (j
= 0; j
< vp
->out_nr
; ++j
) {
549 if (vp
->out
[j
].sn
== gp
->in
[i
].sn
&&
550 vp
->out
[j
].si
== gp
->in
[i
].si
) {
551 mv
= vp
->out
[j
].mask
;
557 for (c
= 0; c
< 4; ++c
, mv
>>= 1, mg
>>= 1) {
562 map
[m
++] = (c
== 3) ? 0x41 : 0x40;
572 nv50_gp_linkage_validate(struct nv50_context
*nv50
)
574 struct nouveau_pushbuf
*push
= nv50
->base
.pushbuf
;
575 struct nv50_program
*vp
= nv50
->vertprog
;
576 struct nv50_program
*gp
= nv50
->gmtyprog
;
583 memset(map
, 0, sizeof(map
));
585 m
= nv50_vp_gp_mapping(map
, m
, vp
, gp
);
589 BEGIN_NV04(push
, NV50_3D(VP_GP_BUILTIN_ATTR_EN
), 1);
590 PUSH_DATA (push
, vp
->vp
.attrs
[2] | gp
->vp
.attrs
[2]);
593 BEGIN_NV04(push
, NV50_3D(VP_RESULT_MAP_SIZE
), 1);
595 BEGIN_NV04(push
, NV50_3D(VP_RESULT_MAP(0)), n
);
596 PUSH_DATAp(push
, map
, n
);
600 nv50_stream_output_validate(struct nv50_context
*nv50
)
602 struct nouveau_pushbuf
*push
= nv50
->base
.pushbuf
;
603 struct nv50_stream_output_state
*so
;
608 so
= nv50
->gmtyprog
? nv50
->gmtyprog
->so
: nv50
->vertprog
->so
;
610 BEGIN_NV04(push
, NV50_3D(STRMOUT_ENABLE
), 1);
612 if (!so
|| !nv50
->num_so_targets
) {
613 if (nv50
->screen
->base
.class_3d
< NVA0_3D_CLASS
) {
614 BEGIN_NV04(push
, NV50_3D(STRMOUT_PRIMITIVE_LIMIT
), 1);
617 BEGIN_NV04(push
, NV50_3D(STRMOUT_PARAMS_LATCH
), 1);
622 /* previous TFB needs to complete */
623 if (nv50
->screen
->base
.class_3d
< NVA0_3D_CLASS
) {
624 BEGIN_NV04(push
, SUBC_3D(NV50_GRAPH_SERIALIZE
), 1);
629 if (nv50
->screen
->base
.class_3d
>= NVA0_3D_CLASS
)
630 ctrl
|= NVA0_3D_STRMOUT_BUFFERS_CTRL_LIMIT_MODE_OFFSET
;
632 BEGIN_NV04(push
, NV50_3D(STRMOUT_BUFFERS_CTRL
), 1);
633 PUSH_DATA (push
, ctrl
);
635 nouveau_bufctx_reset(nv50
->bufctx_3d
, NV50_BIND_SO
);
637 for (i
= 0; i
< nv50
->num_so_targets
; ++i
) {
638 struct nv50_so_target
*targ
= nv50_so_target(nv50
->so_target
[i
]);
639 struct nv04_resource
*buf
= nv04_resource(targ
->pipe
.buffer
);
641 const unsigned n
= nv50
->screen
->base
.class_3d
>= NVA0_3D_CLASS
? 4 : 3;
643 if (n
== 4 && !targ
->clean
)
644 nv84_query_fifo_wait(push
, targ
->pq
);
645 BEGIN_NV04(push
, NV50_3D(STRMOUT_ADDRESS_HIGH(i
)), n
);
646 PUSH_DATAh(push
, buf
->address
+ targ
->pipe
.buffer_offset
);
647 PUSH_DATA (push
, buf
->address
+ targ
->pipe
.buffer_offset
);
648 PUSH_DATA (push
, so
->num_attribs
[i
]);
650 PUSH_DATA(push
, targ
->pipe
.buffer_size
);
653 nv50_query_pushbuf_submit(push
, NVA0_3D_STRMOUT_OFFSET(i
),
656 BEGIN_NV04(push
, NVA0_3D(STRMOUT_OFFSET(i
)), 1);
661 const unsigned limit
= targ
->pipe
.buffer_size
/
662 (so
->stride
[i
] * nv50
->state
.prim_size
);
663 prims
= MIN2(prims
, limit
);
665 targ
->stride
= so
->stride
[i
];
666 BCTX_REFN(nv50
->bufctx_3d
, SO
, buf
, WR
);
669 BEGIN_NV04(push
, NV50_3D(STRMOUT_PRIMITIVE_LIMIT
), 1);
670 PUSH_DATA (push
, prims
);
672 BEGIN_NV04(push
, NV50_3D(STRMOUT_PARAMS_LATCH
), 1);
674 BEGIN_NV04(push
, NV50_3D(STRMOUT_ENABLE
), 1);