2 * Copyright 2008 Ben Skeggs
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.
25 #include "pipe/p_defines.h"
27 #include "util/u_inlines.h"
28 #include "util/u_pack_color.h"
29 #include "util/u_format.h"
30 #include "util/u_math.h"
31 #include "util/u_surface.h"
33 #include "tgsi/tgsi_ureg.h"
35 #include "os/os_thread.h"
37 #include "nv50/nv50_context.h"
38 #include "nv50/nv50_resource.h"
40 #include "nv50/g80_defs.xml.h"
41 #include "nv50/g80_texture.xml.h"
43 /* these are used in nv50_blit.h */
44 #define NV50_ENG2D_SUPPORTED_FORMATS 0xff0843e080608409ULL
45 #define NV50_ENG2D_NOCONVERT_FORMATS 0x0008402000000000ULL
46 #define NV50_ENG2D_LUMINANCE_FORMATS 0x0008402000000000ULL
47 #define NV50_ENG2D_INTENSITY_FORMATS 0x0000000000000000ULL
48 #define NV50_ENG2D_OPERATION_FORMATS 0x060001c000608000ULL
50 #define NOUVEAU_DRIVER 0x50
51 #include "nv50/nv50_blit.h"
54 nv50_2d_format(enum pipe_format format
, bool dst
, bool dst_src_equal
)
56 uint8_t id
= nv50_format_table
[format
].rt
;
58 /* Hardware values for color formats range from 0xc0 to 0xff,
59 * but the 2D engine doesn't support all of them.
61 if ((id
>= 0xc0) && (NV50_ENG2D_SUPPORTED_FORMATS
& (1ULL << (id
- 0xc0))))
63 assert(dst_src_equal
);
65 switch (util_format_get_blocksize(format
)) {
67 return G80_SURFACE_FORMAT_R8_UNORM
;
69 return G80_SURFACE_FORMAT_R16_UNORM
;
71 return G80_SURFACE_FORMAT_BGRA8_UNORM
;
73 return G80_SURFACE_FORMAT_RGBA16_FLOAT
;
75 return G80_SURFACE_FORMAT_RGBA32_FLOAT
;
82 nv50_2d_texture_set(struct nouveau_pushbuf
*push
, int dst
,
83 struct nv50_miptree
*mt
, unsigned level
, unsigned layer
,
84 enum pipe_format pformat
, bool dst_src_pformat_equal
)
86 struct nouveau_bo
*bo
= mt
->base
.bo
;
87 uint32_t width
, height
, depth
;
89 uint32_t mthd
= dst
? NV50_2D_DST_FORMAT
: NV50_2D_SRC_FORMAT
;
90 uint32_t offset
= mt
->level
[level
].offset
;
92 format
= nv50_2d_format(pformat
, dst
, dst_src_pformat_equal
);
94 NOUVEAU_ERR("invalid/unsupported surface format: %s\n",
95 util_format_name(pformat
));
99 width
= u_minify(mt
->base
.base
.width0
, level
) << mt
->ms_x
;
100 height
= u_minify(mt
->base
.base
.height0
, level
) << mt
->ms_y
;
101 depth
= u_minify(mt
->base
.base
.depth0
, level
);
103 offset
= mt
->level
[level
].offset
;
104 if (!mt
->layout_3d
) {
105 offset
+= mt
->layer_stride
* layer
;
110 offset
+= nv50_mt_zslice_offset(mt
, level
, layer
);
114 if (!nouveau_bo_memtype(bo
)) {
115 BEGIN_NV04(push
, SUBC_2D(mthd
), 2);
116 PUSH_DATA (push
, format
);
118 BEGIN_NV04(push
, SUBC_2D(mthd
+ 0x14), 5);
119 PUSH_DATA (push
, mt
->level
[level
].pitch
);
120 PUSH_DATA (push
, width
);
121 PUSH_DATA (push
, height
);
122 PUSH_DATAh(push
, mt
->base
.address
+ offset
);
123 PUSH_DATA (push
, mt
->base
.address
+ offset
);
125 BEGIN_NV04(push
, SUBC_2D(mthd
), 5);
126 PUSH_DATA (push
, format
);
128 PUSH_DATA (push
, mt
->level
[level
].tile_mode
);
129 PUSH_DATA (push
, depth
);
130 PUSH_DATA (push
, layer
);
131 BEGIN_NV04(push
, SUBC_2D(mthd
+ 0x18), 4);
132 PUSH_DATA (push
, width
);
133 PUSH_DATA (push
, height
);
134 PUSH_DATAh(push
, mt
->base
.address
+ offset
);
135 PUSH_DATA (push
, mt
->base
.address
+ offset
);
140 BEGIN_NV04(push
, SUBC_2D(NV50_2D_CLIP_X
), 4);
143 PUSH_DATA (push
, width
);
144 PUSH_DATA (push
, height
);
151 nv50_2d_texture_do_copy(struct nouveau_pushbuf
*push
,
152 struct nv50_miptree
*dst
, unsigned dst_level
,
153 unsigned dx
, unsigned dy
, unsigned dz
,
154 struct nv50_miptree
*src
, unsigned src_level
,
155 unsigned sx
, unsigned sy
, unsigned sz
,
156 unsigned w
, unsigned h
)
158 const enum pipe_format dfmt
= dst
->base
.base
.format
;
159 const enum pipe_format sfmt
= src
->base
.base
.format
;
161 bool eqfmt
= dfmt
== sfmt
;
163 if (!PUSH_SPACE(push
, 2 * 16 + 32))
166 ret
= nv50_2d_texture_set(push
, 1, dst
, dst_level
, dz
, dfmt
, eqfmt
);
170 ret
= nv50_2d_texture_set(push
, 0, src
, src_level
, sz
, sfmt
, eqfmt
);
174 BEGIN_NV04(push
, NV50_2D(BLIT_CONTROL
), 1);
175 PUSH_DATA (push
, NV50_2D_BLIT_CONTROL_FILTER_POINT_SAMPLE
);
176 BEGIN_NV04(push
, NV50_2D(BLIT_DST_X
), 4);
177 PUSH_DATA (push
, dx
<< dst
->ms_x
);
178 PUSH_DATA (push
, dy
<< dst
->ms_y
);
179 PUSH_DATA (push
, w
<< dst
->ms_x
);
180 PUSH_DATA (push
, h
<< dst
->ms_y
);
181 BEGIN_NV04(push
, NV50_2D(BLIT_DU_DX_FRACT
), 4);
186 BEGIN_NV04(push
, NV50_2D(BLIT_SRC_X_FRACT
), 4);
188 PUSH_DATA (push
, sx
<< src
->ms_x
);
190 PUSH_DATA (push
, sy
<< src
->ms_y
);
196 nv50_resource_copy_region(struct pipe_context
*pipe
,
197 struct pipe_resource
*dst
, unsigned dst_level
,
198 unsigned dstx
, unsigned dsty
, unsigned dstz
,
199 struct pipe_resource
*src
, unsigned src_level
,
200 const struct pipe_box
*src_box
)
202 struct nv50_context
*nv50
= nv50_context(pipe
);
205 unsigned dst_layer
= dstz
, src_layer
= src_box
->z
;
207 if (dst
->target
== PIPE_BUFFER
&& src
->target
== PIPE_BUFFER
) {
208 nouveau_copy_buffer(&nv50
->base
,
209 nv04_resource(dst
), dstx
,
210 nv04_resource(src
), src_box
->x
, src_box
->width
);
214 /* 0 and 1 are equal, only supporting 0/1, 2, 4 and 8 */
215 assert((src
->nr_samples
| 1) == (dst
->nr_samples
| 1));
217 m2mf
= (src
->format
== dst
->format
) ||
218 (util_format_get_blocksizebits(src
->format
) ==
219 util_format_get_blocksizebits(dst
->format
));
221 nv04_resource(dst
)->status
|= NOUVEAU_BUFFER_STATUS_GPU_WRITING
;
224 struct nv50_miptree
*src_mt
= nv50_miptree(src
);
225 struct nv50_miptree
*dst_mt
= nv50_miptree(dst
);
226 struct nv50_m2mf_rect drect
, srect
;
228 unsigned nx
= util_format_get_nblocksx(src
->format
, src_box
->width
)
230 unsigned ny
= util_format_get_nblocksy(src
->format
, src_box
->height
)
233 nv50_m2mf_rect_setup(&drect
, dst
, dst_level
, dstx
, dsty
, dstz
);
234 nv50_m2mf_rect_setup(&srect
, src
, src_level
,
235 src_box
->x
, src_box
->y
, src_box
->z
);
237 for (i
= 0; i
< src_box
->depth
; ++i
) {
238 nv50_m2mf_transfer_rect(nv50
, &drect
, &srect
, nx
, ny
);
240 if (dst_mt
->layout_3d
)
243 drect
.base
+= dst_mt
->layer_stride
;
245 if (src_mt
->layout_3d
)
248 srect
.base
+= src_mt
->layer_stride
;
253 assert((src
->format
== dst
->format
) ||
254 (nv50_2d_src_format_faithful(src
->format
) &&
255 nv50_2d_dst_format_faithful(dst
->format
)));
257 BCTX_REFN(nv50
->bufctx
, 2D
, nv04_resource(src
), RD
);
258 BCTX_REFN(nv50
->bufctx
, 2D
, nv04_resource(dst
), WR
);
259 nouveau_pushbuf_bufctx(nv50
->base
.pushbuf
, nv50
->bufctx
);
260 nouveau_pushbuf_validate(nv50
->base
.pushbuf
);
262 for (; dst_layer
< dstz
+ src_box
->depth
; ++dst_layer
, ++src_layer
) {
263 ret
= nv50_2d_texture_do_copy(nv50
->base
.pushbuf
,
264 nv50_miptree(dst
), dst_level
,
265 dstx
, dsty
, dst_layer
,
266 nv50_miptree(src
), src_level
,
267 src_box
->x
, src_box
->y
, src_layer
,
268 src_box
->width
, src_box
->height
);
272 nouveau_bufctx_reset(nv50
->bufctx
, NV50_BIND_2D
);
276 nv50_clear_render_target(struct pipe_context
*pipe
,
277 struct pipe_surface
*dst
,
278 const union pipe_color_union
*color
,
279 unsigned dstx
, unsigned dsty
,
280 unsigned width
, unsigned height
,
281 bool render_condition_enabled
)
283 struct nv50_context
*nv50
= nv50_context(pipe
);
284 struct nouveau_pushbuf
*push
= nv50
->base
.pushbuf
;
285 struct nv50_miptree
*mt
= nv50_miptree(dst
->texture
);
286 struct nv50_surface
*sf
= nv50_surface(dst
);
287 struct nouveau_bo
*bo
= mt
->base
.bo
;
290 assert(dst
->texture
->target
!= PIPE_BUFFER
);
292 BEGIN_NV04(push
, NV50_3D(CLEAR_COLOR(0)), 4);
293 PUSH_DATAf(push
, color
->f
[0]);
294 PUSH_DATAf(push
, color
->f
[1]);
295 PUSH_DATAf(push
, color
->f
[2]);
296 PUSH_DATAf(push
, color
->f
[3]);
298 if (nouveau_pushbuf_space(push
, 64 + sf
->depth
, 1, 0))
301 PUSH_REFN(push
, bo
, mt
->base
.domain
| NOUVEAU_BO_WR
);
303 BEGIN_NV04(push
, NV50_3D(SCREEN_SCISSOR_HORIZ
), 2);
304 PUSH_DATA (push
, ( width
<< 16) | dstx
);
305 PUSH_DATA (push
, (height
<< 16) | dsty
);
306 BEGIN_NV04(push
, NV50_3D(SCISSOR_HORIZ(0)), 2);
307 PUSH_DATA (push
, 8192 << 16);
308 PUSH_DATA (push
, 8192 << 16);
309 nv50
->scissors_dirty
|= 1;
311 BEGIN_NV04(push
, NV50_3D(RT_CONTROL
), 1);
313 BEGIN_NV04(push
, NV50_3D(RT_ADDRESS_HIGH(0)), 5);
314 PUSH_DATAh(push
, mt
->base
.address
+ sf
->offset
);
315 PUSH_DATA (push
, mt
->base
.address
+ sf
->offset
);
316 PUSH_DATA (push
, nv50_format_table
[dst
->format
].rt
);
317 PUSH_DATA (push
, mt
->level
[sf
->base
.u
.tex
.level
].tile_mode
);
318 PUSH_DATA (push
, mt
->layer_stride
>> 2);
319 BEGIN_NV04(push
, NV50_3D(RT_HORIZ(0)), 2);
320 if (nouveau_bo_memtype(bo
))
321 PUSH_DATA(push
, sf
->width
);
323 PUSH_DATA(push
, NV50_3D_RT_HORIZ_LINEAR
| mt
->level
[0].pitch
);
324 PUSH_DATA (push
, sf
->height
);
325 BEGIN_NV04(push
, NV50_3D(RT_ARRAY_MODE
), 1);
327 PUSH_DATA(push
, NV50_3D_RT_ARRAY_MODE_MODE_3D
| 512);
329 PUSH_DATA(push
, 512);
331 BEGIN_NV04(push
, NV50_3D(MULTISAMPLE_MODE
), 1);
332 PUSH_DATA (push
, mt
->ms_mode
);
334 if (!nouveau_bo_memtype(bo
)) {
335 BEGIN_NV04(push
, NV50_3D(ZETA_ENABLE
), 1);
339 /* NOTE: only works with D3D clear flag (5097/0x143c bit 4) */
341 BEGIN_NV04(push
, NV50_3D(VIEWPORT_HORIZ(0)), 2);
342 PUSH_DATA (push
, (width
<< 16) | dstx
);
343 PUSH_DATA (push
, (height
<< 16) | dsty
);
345 if (!render_condition_enabled
) {
346 BEGIN_NV04(push
, NV50_3D(COND_MODE
), 1);
347 PUSH_DATA (push
, NV50_3D_COND_MODE_ALWAYS
);
350 BEGIN_NI04(push
, NV50_3D(CLEAR_BUFFERS
), sf
->depth
);
351 for (z
= 0; z
< sf
->depth
; ++z
) {
352 PUSH_DATA (push
, 0x3c |
353 (z
<< NV50_3D_CLEAR_BUFFERS_LAYER__SHIFT
));
356 if (!render_condition_enabled
) {
357 BEGIN_NV04(push
, NV50_3D(COND_MODE
), 1);
358 PUSH_DATA (push
, nv50
->cond_condmode
);
361 nv50
->dirty_3d
|= NV50_NEW_3D_FRAMEBUFFER
| NV50_NEW_3D_SCISSOR
;
365 nv50_clear_depth_stencil(struct pipe_context
*pipe
,
366 struct pipe_surface
*dst
,
367 unsigned clear_flags
,
370 unsigned dstx
, unsigned dsty
,
371 unsigned width
, unsigned height
,
372 bool render_condition_enabled
)
374 struct nv50_context
*nv50
= nv50_context(pipe
);
375 struct nouveau_pushbuf
*push
= nv50
->base
.pushbuf
;
376 struct nv50_miptree
*mt
= nv50_miptree(dst
->texture
);
377 struct nv50_surface
*sf
= nv50_surface(dst
);
378 struct nouveau_bo
*bo
= mt
->base
.bo
;
382 assert(dst
->texture
->target
!= PIPE_BUFFER
);
383 assert(nouveau_bo_memtype(bo
)); /* ZETA cannot be linear */
385 if (clear_flags
& PIPE_CLEAR_DEPTH
) {
386 BEGIN_NV04(push
, NV50_3D(CLEAR_DEPTH
), 1);
387 PUSH_DATAf(push
, depth
);
388 mode
|= NV50_3D_CLEAR_BUFFERS_Z
;
391 if (clear_flags
& PIPE_CLEAR_STENCIL
) {
392 BEGIN_NV04(push
, NV50_3D(CLEAR_STENCIL
), 1);
393 PUSH_DATA (push
, stencil
& 0xff);
394 mode
|= NV50_3D_CLEAR_BUFFERS_S
;
397 if (nouveau_pushbuf_space(push
, 64 + sf
->depth
, 1, 0))
400 PUSH_REFN(push
, bo
, mt
->base
.domain
| NOUVEAU_BO_WR
);
402 BEGIN_NV04(push
, NV50_3D(SCREEN_SCISSOR_HORIZ
), 2);
403 PUSH_DATA (push
, ( width
<< 16) | dstx
);
404 PUSH_DATA (push
, (height
<< 16) | dsty
);
405 BEGIN_NV04(push
, NV50_3D(SCISSOR_HORIZ(0)), 2);
406 PUSH_DATA (push
, 8192 << 16);
407 PUSH_DATA (push
, 8192 << 16);
408 nv50
->scissors_dirty
|= 1;
410 BEGIN_NV04(push
, NV50_3D(ZETA_ADDRESS_HIGH
), 5);
411 PUSH_DATAh(push
, mt
->base
.address
+ sf
->offset
);
412 PUSH_DATA (push
, mt
->base
.address
+ sf
->offset
);
413 PUSH_DATA (push
, nv50_format_table
[dst
->format
].rt
);
414 PUSH_DATA (push
, mt
->level
[sf
->base
.u
.tex
.level
].tile_mode
);
415 PUSH_DATA (push
, mt
->layer_stride
>> 2);
416 BEGIN_NV04(push
, NV50_3D(ZETA_ENABLE
), 1);
418 BEGIN_NV04(push
, NV50_3D(ZETA_HORIZ
), 3);
419 PUSH_DATA (push
, sf
->width
);
420 PUSH_DATA (push
, sf
->height
);
421 PUSH_DATA (push
, (1 << 16) | 1);
423 BEGIN_NV04(push
, NV50_3D(RT_ARRAY_MODE
), 1);
424 PUSH_DATA (push
, 512);
426 BEGIN_NV04(push
, NV50_3D(MULTISAMPLE_MODE
), 1);
427 PUSH_DATA (push
, mt
->ms_mode
);
429 BEGIN_NV04(push
, NV50_3D(VIEWPORT_HORIZ(0)), 2);
430 PUSH_DATA (push
, (width
<< 16) | dstx
);
431 PUSH_DATA (push
, (height
<< 16) | dsty
);
433 if (!render_condition_enabled
) {
434 BEGIN_NV04(push
, NV50_3D(COND_MODE
), 1);
435 PUSH_DATA (push
, NV50_3D_COND_MODE_ALWAYS
);
438 BEGIN_NI04(push
, NV50_3D(CLEAR_BUFFERS
), sf
->depth
);
439 for (z
= 0; z
< sf
->depth
; ++z
) {
440 PUSH_DATA (push
, mode
|
441 (z
<< NV50_3D_CLEAR_BUFFERS_LAYER__SHIFT
));
444 if (!render_condition_enabled
) {
445 BEGIN_NV04(push
, NV50_3D(COND_MODE
), 1);
446 PUSH_DATA (push
, nv50
->cond_condmode
);
449 nv50
->dirty_3d
|= NV50_NEW_3D_FRAMEBUFFER
| NV50_NEW_3D_SCISSOR
;
453 nv50_clear_texture(struct pipe_context
*pipe
,
454 struct pipe_resource
*res
,
456 const struct pipe_box
*box
,
459 struct pipe_surface tmpl
= {{0}}, *sf
;
461 tmpl
.format
= res
->format
;
462 tmpl
.u
.tex
.first_layer
= box
->z
;
463 tmpl
.u
.tex
.last_layer
= box
->z
+ box
->depth
- 1;
464 tmpl
.u
.tex
.level
= level
;
465 sf
= pipe
->create_surface(pipe
, res
, &tmpl
);
469 if (util_format_is_depth_or_stencil(res
->format
)) {
473 const struct util_format_description
*desc
=
474 util_format_description(res
->format
);
476 if (util_format_has_depth(desc
)) {
477 clear
|= PIPE_CLEAR_DEPTH
;
478 desc
->unpack_z_float(&depth
, 0, data
, 0, 1, 1);
480 if (util_format_has_stencil(desc
)) {
481 clear
|= PIPE_CLEAR_STENCIL
;
482 desc
->unpack_s_8uint(&stencil
, 0, data
, 0, 1, 1);
484 pipe
->clear_depth_stencil(pipe
, sf
, clear
, depth
, stencil
,
485 box
->x
, box
->y
, box
->width
, box
->height
, false);
487 union pipe_color_union color
;
489 switch (util_format_get_blocksizebits(res
->format
)) {
491 sf
->format
= PIPE_FORMAT_R32G32B32A32_UINT
;
492 memcpy(&color
.ui
, data
, 128 / 8);
495 sf
->format
= PIPE_FORMAT_R32G32_UINT
;
496 memcpy(&color
.ui
, data
, 64 / 8);
497 memset(&color
.ui
[2], 0, 64 / 8);
500 sf
->format
= PIPE_FORMAT_R32_UINT
;
501 memcpy(&color
.ui
, data
, 32 / 8);
502 memset(&color
.ui
[1], 0, 96 / 8);
505 sf
->format
= PIPE_FORMAT_R16_UINT
;
506 color
.ui
[0] = util_cpu_to_le32(
507 util_le16_to_cpu(*(unsigned short *)data
));
508 memset(&color
.ui
[1], 0, 96 / 8);
511 sf
->format
= PIPE_FORMAT_R8_UINT
;
512 color
.ui
[0] = util_cpu_to_le32(*(unsigned char *)data
);
513 memset(&color
.ui
[1], 0, 96 / 8);
516 assert(!"Unknown texel element size");
520 pipe
->clear_render_target(pipe
, sf
, &color
,
521 box
->x
, box
->y
, box
->width
, box
->height
, false);
523 pipe
->surface_destroy(pipe
, sf
);
527 nv50_clear(struct pipe_context
*pipe
, unsigned buffers
,
528 const union pipe_color_union
*color
,
529 double depth
, unsigned stencil
)
531 struct nv50_context
*nv50
= nv50_context(pipe
);
532 struct nouveau_pushbuf
*push
= nv50
->base
.pushbuf
;
533 struct pipe_framebuffer_state
*fb
= &nv50
->framebuffer
;
537 /* don't need NEW_BLEND, COLOR_MASK doesn't affect CLEAR_BUFFERS */
538 if (!nv50_state_validate_3d(nv50
, NV50_NEW_3D_FRAMEBUFFER
))
541 /* We have to clear ALL of the layers, not up to the min number of layers
542 * of any attachment. */
543 BEGIN_NV04(push
, NV50_3D(RT_ARRAY_MODE
), 1);
544 PUSH_DATA (push
, (nv50
->rt_array_mode
& NV50_3D_RT_ARRAY_MODE_MODE_3D
) | 512);
546 if (buffers
& PIPE_CLEAR_COLOR
&& fb
->nr_cbufs
) {
547 BEGIN_NV04(push
, NV50_3D(CLEAR_COLOR(0)), 4);
548 PUSH_DATAf(push
, color
->f
[0]);
549 PUSH_DATAf(push
, color
->f
[1]);
550 PUSH_DATAf(push
, color
->f
[2]);
551 PUSH_DATAf(push
, color
->f
[3]);
552 if (buffers
& PIPE_CLEAR_COLOR0
)
554 NV50_3D_CLEAR_BUFFERS_R
| NV50_3D_CLEAR_BUFFERS_G
|
555 NV50_3D_CLEAR_BUFFERS_B
| NV50_3D_CLEAR_BUFFERS_A
;
558 if (buffers
& PIPE_CLEAR_DEPTH
) {
559 BEGIN_NV04(push
, NV50_3D(CLEAR_DEPTH
), 1);
560 PUSH_DATA (push
, fui(depth
));
561 mode
|= NV50_3D_CLEAR_BUFFERS_Z
;
564 if (buffers
& PIPE_CLEAR_STENCIL
) {
565 BEGIN_NV04(push
, NV50_3D(CLEAR_STENCIL
), 1);
566 PUSH_DATA (push
, stencil
& 0xff);
567 mode
|= NV50_3D_CLEAR_BUFFERS_S
;
571 int zs_layers
= 0, color0_layers
= 0;
572 if (fb
->cbufs
[0] && (mode
& 0x3c))
573 color0_layers
= nv50_surface(fb
->cbufs
[0])->depth
;
574 if (fb
->zsbuf
&& (mode
& ~0x3c))
575 zs_layers
= nv50_surface(fb
->zsbuf
)->depth
;
577 for (j
= 0; j
< MIN2(zs_layers
, color0_layers
); j
++) {
578 BEGIN_NV04(push
, NV50_3D(CLEAR_BUFFERS
), 1);
579 PUSH_DATA(push
, mode
| (j
<< NV50_3D_CLEAR_BUFFERS_LAYER__SHIFT
));
581 for (k
= j
; k
< zs_layers
; k
++) {
582 BEGIN_NV04(push
, NV50_3D(CLEAR_BUFFERS
), 1);
583 PUSH_DATA(push
, (mode
& ~0x3c) | (k
<< NV50_3D_CLEAR_BUFFERS_LAYER__SHIFT
));
585 for (k
= j
; k
< color0_layers
; k
++) {
586 BEGIN_NV04(push
, NV50_3D(CLEAR_BUFFERS
), 1);
587 PUSH_DATA(push
, (mode
& 0x3c) | (k
<< NV50_3D_CLEAR_BUFFERS_LAYER__SHIFT
));
591 for (i
= 1; i
< fb
->nr_cbufs
; i
++) {
592 struct pipe_surface
*sf
= fb
->cbufs
[i
];
593 if (!sf
|| !(buffers
& (PIPE_CLEAR_COLOR0
<< i
)))
595 for (j
= 0; j
< nv50_surface(sf
)->depth
; j
++) {
596 BEGIN_NV04(push
, NV50_3D(CLEAR_BUFFERS
), 1);
597 PUSH_DATA (push
, (i
<< 6) | 0x3c |
598 (j
<< NV50_3D_CLEAR_BUFFERS_LAYER__SHIFT
));
602 /* restore the array mode */
603 BEGIN_NV04(push
, NV50_3D(RT_ARRAY_MODE
), 1);
604 PUSH_DATA (push
, nv50
->rt_array_mode
);
608 nv50_clear_buffer_push(struct pipe_context
*pipe
,
609 struct pipe_resource
*res
,
610 unsigned offset
, unsigned size
,
611 const void *data
, int data_size
)
613 struct nv50_context
*nv50
= nv50_context(pipe
);
614 struct nouveau_pushbuf
*push
= nv50
->base
.pushbuf
;
615 struct nv04_resource
*buf
= nv04_resource(res
);
616 unsigned count
= (size
+ 3) / 4;
617 unsigned xcoord
= offset
& 0xff;
620 if (data_size
== 1) {
621 tmp
= *(unsigned char *)data
;
622 tmp
= (tmp
<< 24) | (tmp
<< 16) | (tmp
<< 8) | tmp
;
625 } else if (data_size
== 2) {
626 tmp
= *(unsigned short *)data
;
627 tmp
= (tmp
<< 16) | tmp
;
632 unsigned data_words
= data_size
/ 4;
634 nouveau_bufctx_refn(nv50
->bufctx
, 0, buf
->bo
, buf
->domain
| NOUVEAU_BO_WR
);
635 nouveau_pushbuf_bufctx(push
, nv50
->bufctx
);
636 nouveau_pushbuf_validate(push
);
640 BEGIN_NV04(push
, NV50_2D(DST_FORMAT
), 2);
641 PUSH_DATA (push
, G80_SURFACE_FORMAT_R8_UNORM
);
643 BEGIN_NV04(push
, NV50_2D(DST_PITCH
), 5);
644 PUSH_DATA (push
, 262144);
645 PUSH_DATA (push
, 65536);
647 PUSH_DATAh(push
, buf
->address
+ offset
);
648 PUSH_DATA (push
, buf
->address
+ offset
);
649 BEGIN_NV04(push
, NV50_2D(SIFC_BITMAP_ENABLE
), 2);
651 PUSH_DATA (push
, G80_SURFACE_FORMAT_R8_UNORM
);
652 BEGIN_NV04(push
, NV50_2D(SIFC_WIDTH
), 10);
653 PUSH_DATA (push
, size
);
660 PUSH_DATA (push
, xcoord
);
665 unsigned nr_data
= MIN2(count
, NV04_PFIFO_MAX_PACKET_LEN
) / data_words
;
666 unsigned nr
= nr_data
* data_words
;
668 BEGIN_NI04(push
, NV50_2D(SIFC_DATA
), nr
);
669 for (i
= 0; i
< nr_data
; i
++)
670 PUSH_DATAp(push
, data
, data_words
);
676 nouveau_fence_ref(nv50
->screen
->base
.fence
.current
, &buf
->fence
);
677 nouveau_fence_ref(nv50
->screen
->base
.fence
.current
, &buf
->fence_wr
);
680 nouveau_bufctx_reset(nv50
->bufctx
, 0);
684 nv50_clear_buffer(struct pipe_context
*pipe
,
685 struct pipe_resource
*res
,
686 unsigned offset
, unsigned size
,
687 const void *data
, int data_size
)
689 struct nv50_context
*nv50
= nv50_context(pipe
);
690 struct nouveau_pushbuf
*push
= nv50
->base
.pushbuf
;
691 struct nv04_resource
*buf
= (struct nv04_resource
*)res
;
692 union pipe_color_union color
;
693 enum pipe_format dst_fmt
;
694 unsigned width
, height
, elements
;
696 assert(res
->target
== PIPE_BUFFER
);
697 assert(nouveau_bo_memtype(buf
->bo
) == 0);
701 dst_fmt
= PIPE_FORMAT_R32G32B32A32_UINT
;
702 memcpy(&color
.ui
, data
, 16);
705 dst_fmt
= PIPE_FORMAT_R32G32_UINT
;
706 memcpy(&color
.ui
, data
, 8);
707 memset(&color
.ui
[2], 0, 8);
710 dst_fmt
= PIPE_FORMAT_R32_UINT
;
711 memcpy(&color
.ui
, data
, 4);
712 memset(&color
.ui
[1], 0, 12);
715 dst_fmt
= PIPE_FORMAT_R16_UINT
;
716 color
.ui
[0] = util_cpu_to_le32(
717 util_le16_to_cpu(*(unsigned short *)data
));
718 memset(&color
.ui
[1], 0, 12);
721 dst_fmt
= PIPE_FORMAT_R8_UINT
;
722 color
.ui
[0] = util_cpu_to_le32(*(unsigned char *)data
);
723 memset(&color
.ui
[1], 0, 12);
726 assert(!"Unsupported element size");
730 assert(size
% data_size
== 0);
733 unsigned fixup_size
= MIN2(size
, align(offset
, 0x100) - offset
);
734 assert(fixup_size
% data_size
== 0);
735 nv50_clear_buffer_push(pipe
, res
, offset
, fixup_size
, data
, data_size
);
736 offset
+= fixup_size
;
742 elements
= size
/ data_size
;
743 height
= (elements
+ 8191) / 8192;
744 width
= elements
/ height
;
749 BEGIN_NV04(push
, NV50_3D(CLEAR_COLOR(0)), 4);
750 PUSH_DATAf(push
, color
.f
[0]);
751 PUSH_DATAf(push
, color
.f
[1]);
752 PUSH_DATAf(push
, color
.f
[2]);
753 PUSH_DATAf(push
, color
.f
[3]);
755 if (nouveau_pushbuf_space(push
, 64, 1, 0))
758 PUSH_REFN(push
, buf
->bo
, buf
->domain
| NOUVEAU_BO_WR
);
760 BEGIN_NV04(push
, NV50_3D(SCREEN_SCISSOR_HORIZ
), 2);
761 PUSH_DATA (push
, width
<< 16);
762 PUSH_DATA (push
, height
<< 16);
763 BEGIN_NV04(push
, NV50_3D(SCISSOR_HORIZ(0)), 2);
764 PUSH_DATA (push
, 8192 << 16);
765 PUSH_DATA (push
, 8192 << 16);
766 nv50
->scissors_dirty
|= 1;
768 BEGIN_NV04(push
, NV50_3D(RT_CONTROL
), 1);
770 BEGIN_NV04(push
, NV50_3D(RT_ADDRESS_HIGH(0)), 5);
771 PUSH_DATAh(push
, buf
->address
+ offset
);
772 PUSH_DATA (push
, buf
->address
+ offset
);
773 PUSH_DATA (push
, nv50_format_table
[dst_fmt
].rt
);
776 BEGIN_NV04(push
, NV50_3D(RT_HORIZ(0)), 2);
777 PUSH_DATA (push
, NV50_3D_RT_HORIZ_LINEAR
| align(width
* data_size
, 0x100));
778 PUSH_DATA (push
, height
);
779 BEGIN_NV04(push
, NV50_3D(ZETA_ENABLE
), 1);
781 BEGIN_NV04(push
, NV50_3D(MULTISAMPLE_MODE
), 1);
784 /* NOTE: only works with D3D clear flag (5097/0x143c bit 4) */
786 BEGIN_NV04(push
, NV50_3D(VIEWPORT_HORIZ(0)), 2);
787 PUSH_DATA (push
, (width
<< 16));
788 PUSH_DATA (push
, (height
<< 16));
790 BEGIN_NV04(push
, NV50_3D(COND_MODE
), 1);
791 PUSH_DATA (push
, NV50_3D_COND_MODE_ALWAYS
);
793 BEGIN_NI04(push
, NV50_3D(CLEAR_BUFFERS
), 1);
794 PUSH_DATA (push
, 0x3c);
796 BEGIN_NV04(push
, NV50_3D(COND_MODE
), 1);
797 PUSH_DATA (push
, nv50
->cond_condmode
);
800 nouveau_fence_ref(nv50
->screen
->base
.fence
.current
, &buf
->fence
);
801 nouveau_fence_ref(nv50
->screen
->base
.fence
.current
, &buf
->fence_wr
);
804 if (width
* height
!= elements
) {
805 offset
+= width
* height
* data_size
;
806 width
= elements
- width
* height
;
807 nv50_clear_buffer_push(pipe
, res
, offset
, width
* data_size
,
811 nv50
->dirty_3d
|= NV50_NEW_3D_FRAMEBUFFER
| NV50_NEW_3D_SCISSOR
;
814 /* =============================== BLIT CODE ===================================
819 struct nv50_program
*fp
[NV50_BLIT_MAX_TEXTURE_TYPES
][NV50_BLIT_MODES
];
820 struct nv50_program vp
;
822 struct nv50_tsc_entry sampler
[2]; /* nearest, bilinear */
829 struct nv50_context
*nv50
;
830 struct nv50_program
*fp
;
834 uint8_t render_condition_enable
;
835 enum pipe_texture_target target
;
837 struct pipe_framebuffer_state fb
;
838 struct nv50_window_rect_stateobj window_rect
;
839 struct nv50_rasterizer_stateobj
*rast
;
840 struct nv50_program
*vp
;
841 struct nv50_program
*gp
;
842 struct nv50_program
*fp
;
843 unsigned num_textures
[3];
844 unsigned num_samplers
[3];
845 struct pipe_sampler_view
*texture
[2];
846 struct nv50_tsc_entry
*sampler
[2];
847 unsigned min_samples
;
850 struct nv50_rasterizer_stateobj rast
;
854 nv50_blitter_make_vp(struct nv50_blitter
*blit
)
856 static const uint32_t code
[] =
858 0x10000001, 0x0423c788, /* mov b32 o[0x00] s[0x00] */ /* HPOS.x */
859 0x10000205, 0x0423c788, /* mov b32 o[0x04] s[0x04] */ /* HPOS.y */
860 0x10000409, 0x0423c788, /* mov b32 o[0x08] s[0x08] */ /* TEXC.x */
861 0x1000060d, 0x0423c788, /* mov b32 o[0x0c] s[0x0c] */ /* TEXC.y */
862 0x10000811, 0x0423c789, /* mov b32 o[0x10] s[0x10] */ /* TEXC.z */
865 blit
->vp
.type
= PIPE_SHADER_VERTEX
;
866 blit
->vp
.translated
= true;
867 blit
->vp
.code
= (uint32_t *)code
; /* const_cast */
868 blit
->vp
.code_size
= sizeof(code
);
869 blit
->vp
.max_gpr
= 4;
870 blit
->vp
.max_out
= 5;
872 blit
->vp
.out
[0].mask
= 0x3;
873 blit
->vp
.out
[0].sn
= TGSI_SEMANTIC_POSITION
;
874 blit
->vp
.out
[1].hw
= 2;
875 blit
->vp
.out
[1].mask
= 0x7;
876 blit
->vp
.out
[1].sn
= TGSI_SEMANTIC_GENERIC
;
877 blit
->vp
.out
[1].si
= 0;
878 blit
->vp
.vp
.attrs
[0] = 0x73;
879 blit
->vp
.vp
.psiz
= 0x40;
880 blit
->vp
.vp
.edgeflag
= 0x40;
884 nv50_blitter_make_fp(struct pipe_context
*pipe
,
886 enum pipe_texture_target ptarg
)
888 struct ureg_program
*ureg
;
891 struct ureg_dst data
;
893 const unsigned target
= nv50_blit_get_tgsi_texture_target(ptarg
);
895 bool tex_rgbaz
= false;
897 bool cvt_un8
= false;
899 if (mode
!= NV50_BLIT_MODE_PASS
&&
900 mode
!= NV50_BLIT_MODE_Z24X8
&&
901 mode
!= NV50_BLIT_MODE_X8Z24
)
904 if (mode
!= NV50_BLIT_MODE_X24S8
&&
905 mode
!= NV50_BLIT_MODE_S8X24
&&
906 mode
!= NV50_BLIT_MODE_XS
)
909 if (mode
!= NV50_BLIT_MODE_PASS
&&
910 mode
!= NV50_BLIT_MODE_ZS
&&
911 mode
!= NV50_BLIT_MODE_XS
)
914 ureg
= ureg_create(PIPE_SHADER_FRAGMENT
);
918 out
= ureg_DECL_output(ureg
, TGSI_SEMANTIC_COLOR
, 0);
919 tc
= ureg_DECL_fs_input(
920 ureg
, TGSI_SEMANTIC_GENERIC
, 0, TGSI_INTERPOLATE_LINEAR
);
922 if (ptarg
== PIPE_TEXTURE_1D_ARRAY
) {
923 /* Adjust coordinates. Depth is in z, but TEX expects it to be in y. */
924 tc
= ureg_swizzle(tc
, TGSI_SWIZZLE_X
, TGSI_SWIZZLE_Z
,
925 TGSI_SWIZZLE_Z
, TGSI_SWIZZLE_Z
);
928 data
= ureg_DECL_temporary(ureg
);
931 ureg_TEX(ureg
, ureg_writemask(data
, TGSI_WRITEMASK_X
),
932 target
, tc
, ureg_DECL_sampler(ureg
, 1));
933 ureg_MOV(ureg
, ureg_writemask(data
, TGSI_WRITEMASK_Y
),
934 ureg_scalar(ureg_src(data
), TGSI_SWIZZLE_X
));
937 const unsigned mask
= (mode
== NV50_BLIT_MODE_PASS
) ?
938 TGSI_WRITEMASK_XYZW
: TGSI_WRITEMASK_X
;
939 ureg_TEX(ureg
, ureg_writemask(data
, mask
),
940 target
, tc
, ureg_DECL_sampler(ureg
, 0));
944 struct ureg_src mask
;
945 struct ureg_src scale
;
946 struct ureg_dst outz
;
947 struct ureg_dst outs
;
948 struct ureg_dst zdst3
= ureg_writemask(data
, TGSI_WRITEMASK_XYZ
);
949 struct ureg_dst zdst
= ureg_writemask(data
, TGSI_WRITEMASK_X
);
950 struct ureg_dst sdst
= ureg_writemask(data
, TGSI_WRITEMASK_Y
);
951 struct ureg_src zsrc3
= ureg_src(data
);
952 struct ureg_src zsrc
= ureg_scalar(zsrc3
, TGSI_SWIZZLE_X
);
953 struct ureg_src ssrc
= ureg_scalar(zsrc3
, TGSI_SWIZZLE_Y
);
954 struct ureg_src zshuf
;
956 mask
= ureg_imm3u(ureg
, 0x0000ff, 0x00ff00, 0xff0000);
957 scale
= ureg_imm4f(ureg
,
958 1.0f
/ 0x0000ff, 1.0f
/ 0x00ff00, 1.0f
/ 0xff0000,
961 if (mode
== NV50_BLIT_MODE_Z24S8
||
962 mode
== NV50_BLIT_MODE_X24S8
||
963 mode
== NV50_BLIT_MODE_Z24X8
) {
964 outz
= ureg_writemask(out
, TGSI_WRITEMASK_XYZ
);
965 outs
= ureg_writemask(out
, TGSI_WRITEMASK_W
);
966 zshuf
= ureg_src(data
);
968 outz
= ureg_writemask(out
, TGSI_WRITEMASK_YZW
);
969 outs
= ureg_writemask(out
, TGSI_WRITEMASK_X
);
970 zshuf
= ureg_swizzle(zsrc3
, TGSI_SWIZZLE_W
,
971 TGSI_SWIZZLE_X
, TGSI_SWIZZLE_Y
, TGSI_SWIZZLE_Z
);
975 ureg_I2F(ureg
, sdst
, ssrc
);
976 ureg_MUL(ureg
, outs
, ssrc
, ureg_scalar(scale
, TGSI_SWIZZLE_X
));
980 ureg_MUL(ureg
, zdst
, zsrc
, ureg_scalar(scale
, TGSI_SWIZZLE_W
));
981 ureg_F2I(ureg
, zdst
, zsrc
);
982 ureg_AND(ureg
, zdst3
, zsrc
, mask
);
983 ureg_I2F(ureg
, zdst3
, zsrc3
);
984 ureg_MUL(ureg
, zdst3
, zsrc3
, scale
);
985 ureg_MOV(ureg
, outz
, zshuf
);
988 unsigned mask
= TGSI_WRITEMASK_XYZW
;
990 if (mode
!= NV50_BLIT_MODE_PASS
) {
991 mask
&= ~TGSI_WRITEMASK_ZW
;
993 mask
= TGSI_WRITEMASK_X
;
995 mask
= TGSI_WRITEMASK_Y
;
997 ureg_MOV(ureg
, ureg_writemask(out
, mask
), ureg_src(data
));
1001 return ureg_create_shader_and_destroy(ureg
, pipe
);
1005 nv50_blitter_make_sampler(struct nv50_blitter
*blit
)
1007 /* clamp to edge, min/max lod = 0, nearest filtering */
1009 blit
->sampler
[0].id
= -1;
1011 blit
->sampler
[0].tsc
[0] = G80_TSC_0_SRGB_CONVERSION
|
1012 (G80_TSC_WRAP_CLAMP_TO_EDGE
<< G80_TSC_0_ADDRESS_U__SHIFT
) |
1013 (G80_TSC_WRAP_CLAMP_TO_EDGE
<< G80_TSC_0_ADDRESS_V__SHIFT
) |
1014 (G80_TSC_WRAP_CLAMP_TO_EDGE
<< G80_TSC_0_ADDRESS_P__SHIFT
);
1015 blit
->sampler
[0].tsc
[1] =
1016 G80_TSC_1_MAG_FILTER_NEAREST
|
1017 G80_TSC_1_MIN_FILTER_NEAREST
|
1018 G80_TSC_1_MIP_FILTER_NONE
;
1020 /* clamp to edge, min/max lod = 0, bilinear filtering */
1022 blit
->sampler
[1].id
= -1;
1024 blit
->sampler
[1].tsc
[0] = blit
->sampler
[0].tsc
[0];
1025 blit
->sampler
[1].tsc
[1] =
1026 G80_TSC_1_MAG_FILTER_LINEAR
|
1027 G80_TSC_1_MIN_FILTER_LINEAR
|
1028 G80_TSC_1_MIP_FILTER_NONE
;
1032 nv50_blit_select_mode(const struct pipe_blit_info
*info
)
1034 const unsigned mask
= info
->mask
;
1036 switch (info
->dst
.resource
->format
) {
1037 case PIPE_FORMAT_Z24_UNORM_S8_UINT
:
1038 case PIPE_FORMAT_Z24X8_UNORM
:
1039 case PIPE_FORMAT_X24S8_UINT
:
1040 switch (mask
& PIPE_MASK_ZS
) {
1041 case PIPE_MASK_ZS
: return NV50_BLIT_MODE_Z24S8
;
1042 case PIPE_MASK_Z
: return NV50_BLIT_MODE_Z24X8
;
1044 return NV50_BLIT_MODE_X24S8
;
1046 case PIPE_FORMAT_S8_UINT_Z24_UNORM
:
1047 case PIPE_FORMAT_X8Z24_UNORM
:
1048 case PIPE_FORMAT_S8X24_UINT
:
1049 switch (mask
& PIPE_MASK_ZS
) {
1050 case PIPE_MASK_ZS
: return NV50_BLIT_MODE_S8Z24
;
1051 case PIPE_MASK_Z
: return NV50_BLIT_MODE_X8Z24
;
1053 return NV50_BLIT_MODE_S8X24
;
1055 case PIPE_FORMAT_Z32_FLOAT
:
1056 case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
:
1057 case PIPE_FORMAT_X32_S8X24_UINT
:
1058 switch (mask
& PIPE_MASK_ZS
) {
1059 case PIPE_MASK_ZS
: return NV50_BLIT_MODE_ZS
;
1060 case PIPE_MASK_Z
: return NV50_BLIT_MODE_PASS
;
1062 return NV50_BLIT_MODE_XS
;
1065 return NV50_BLIT_MODE_PASS
;
1070 nv50_blit_select_fp(struct nv50_blitctx
*ctx
, const struct pipe_blit_info
*info
)
1072 struct nv50_blitter
*blitter
= ctx
->nv50
->screen
->blitter
;
1074 const enum pipe_texture_target ptarg
=
1075 nv50_blit_reinterpret_pipe_texture_target(info
->src
.resource
->target
);
1077 const unsigned targ
= nv50_blit_texture_type(ptarg
);
1078 const unsigned mode
= ctx
->mode
;
1080 if (!blitter
->fp
[targ
][mode
]) {
1081 mtx_lock(&blitter
->mutex
);
1082 if (!blitter
->fp
[targ
][mode
])
1083 blitter
->fp
[targ
][mode
] =
1084 nv50_blitter_make_fp(&ctx
->nv50
->base
.pipe
, mode
, ptarg
);
1085 mtx_unlock(&blitter
->mutex
);
1087 ctx
->fp
= blitter
->fp
[targ
][mode
];
1091 nv50_blit_set_dst(struct nv50_blitctx
*ctx
,
1092 struct pipe_resource
*res
, unsigned level
, unsigned layer
,
1093 enum pipe_format format
)
1095 struct nv50_context
*nv50
= ctx
->nv50
;
1096 struct pipe_context
*pipe
= &nv50
->base
.pipe
;
1097 struct pipe_surface templ
;
1099 if (util_format_is_depth_or_stencil(format
))
1100 templ
.format
= nv50_blit_zeta_to_colour_format(format
);
1102 templ
.format
= format
;
1104 templ
.u
.tex
.level
= level
;
1105 templ
.u
.tex
.first_layer
= templ
.u
.tex
.last_layer
= layer
;
1108 templ
.u
.tex
.first_layer
= 0;
1109 templ
.u
.tex
.last_layer
=
1110 (res
->target
== PIPE_TEXTURE_3D
? res
->depth0
: res
->array_size
) - 1;
1113 nv50
->framebuffer
.cbufs
[0] = nv50_miptree_surface_new(pipe
, res
, &templ
);
1114 nv50
->framebuffer
.nr_cbufs
= 1;
1115 nv50
->framebuffer
.zsbuf
= NULL
;
1116 nv50
->framebuffer
.width
= nv50
->framebuffer
.cbufs
[0]->width
;
1117 nv50
->framebuffer
.height
= nv50
->framebuffer
.cbufs
[0]->height
;
1121 nv50_blit_set_src(struct nv50_blitctx
*blit
,
1122 struct pipe_resource
*res
, unsigned level
, unsigned layer
,
1123 enum pipe_format format
, const uint8_t filter
)
1125 struct nv50_context
*nv50
= blit
->nv50
;
1126 struct pipe_context
*pipe
= &nv50
->base
.pipe
;
1127 struct pipe_sampler_view templ
;
1129 enum pipe_texture_target target
;
1131 target
= nv50_blit_reinterpret_pipe_texture_target(res
->target
);
1133 templ
.format
= format
;
1134 templ
.u
.tex
.first_level
= templ
.u
.tex
.last_level
= level
;
1135 templ
.u
.tex
.first_layer
= templ
.u
.tex
.last_layer
= layer
;
1136 templ
.swizzle_r
= PIPE_SWIZZLE_X
;
1137 templ
.swizzle_g
= PIPE_SWIZZLE_Y
;
1138 templ
.swizzle_b
= PIPE_SWIZZLE_Z
;
1139 templ
.swizzle_a
= PIPE_SWIZZLE_W
;
1142 templ
.u
.tex
.first_layer
= 0;
1143 templ
.u
.tex
.last_layer
=
1144 (res
->target
== PIPE_TEXTURE_3D
? res
->depth0
: res
->array_size
) - 1;
1147 flags
= res
->last_level
? 0 : NV50_TEXVIEW_SCALED_COORDS
;
1148 flags
|= NV50_TEXVIEW_ACCESS_RESOLVE
;
1149 if (filter
&& res
->nr_samples
== 8)
1150 flags
|= NV50_TEXVIEW_FILTER_MSAA8
;
1152 nv50
->textures
[2][0] = nv50_create_texture_view(
1153 pipe
, res
, &templ
, flags
, target
);
1154 nv50
->textures
[2][1] = NULL
;
1156 nv50
->num_textures
[0] = nv50
->num_textures
[1] = 0;
1157 nv50
->num_textures
[2] = 1;
1159 templ
.format
= nv50_zs_to_s_format(format
);
1160 if (templ
.format
!= res
->format
) {
1161 nv50
->textures
[2][1] = nv50_create_texture_view(
1162 pipe
, res
, &templ
, flags
, target
);
1163 nv50
->num_textures
[2] = 2;
1168 nv50_blitctx_prepare_state(struct nv50_blitctx
*blit
)
1170 struct nouveau_pushbuf
*push
= blit
->nv50
->base
.pushbuf
;
1172 if (blit
->nv50
->cond_query
&& !blit
->render_condition_enable
) {
1173 BEGIN_NV04(push
, NV50_3D(COND_MODE
), 1);
1174 PUSH_DATA (push
, NV50_3D_COND_MODE_ALWAYS
);
1178 BEGIN_NV04(push
, NV50_3D(COLOR_MASK(0)), 1);
1179 PUSH_DATA (push
, blit
->color_mask
);
1180 BEGIN_NV04(push
, NV50_3D(BLEND_ENABLE(0)), 1);
1181 PUSH_DATA (push
, 0);
1182 BEGIN_NV04(push
, NV50_3D(LOGIC_OP_ENABLE
), 1);
1183 PUSH_DATA (push
, 0);
1185 /* rasterizer state */
1186 #ifndef NV50_SCISSORS_CLIPPING
1187 BEGIN_NV04(push
, NV50_3D(SCISSOR_ENABLE(0)), 1);
1188 PUSH_DATA (push
, 1);
1190 BEGIN_NV04(push
, NV50_3D(VERTEX_TWO_SIDE_ENABLE
), 1);
1191 PUSH_DATA (push
, 0);
1192 BEGIN_NV04(push
, NV50_3D(FRAG_COLOR_CLAMP_EN
), 1);
1193 PUSH_DATA (push
, 0);
1194 BEGIN_NV04(push
, NV50_3D(MULTISAMPLE_ENABLE
), 1);
1195 PUSH_DATA (push
, 0);
1196 BEGIN_NV04(push
, NV50_3D(MSAA_MASK(0)), 4);
1197 PUSH_DATA (push
, 0xffff);
1198 PUSH_DATA (push
, 0xffff);
1199 PUSH_DATA (push
, 0xffff);
1200 PUSH_DATA (push
, 0xffff);
1201 BEGIN_NV04(push
, NV50_3D(POLYGON_MODE_FRONT
), 3);
1202 PUSH_DATA (push
, NV50_3D_POLYGON_MODE_FRONT_FILL
);
1203 PUSH_DATA (push
, NV50_3D_POLYGON_MODE_BACK_FILL
);
1204 PUSH_DATA (push
, 0);
1205 BEGIN_NV04(push
, NV50_3D(CULL_FACE_ENABLE
), 1);
1206 PUSH_DATA (push
, 0);
1207 BEGIN_NV04(push
, NV50_3D(POLYGON_STIPPLE_ENABLE
), 1);
1208 PUSH_DATA (push
, 0);
1209 BEGIN_NV04(push
, NV50_3D(POLYGON_OFFSET_FILL_ENABLE
), 1);
1210 PUSH_DATA (push
, 0);
1213 BEGIN_NV04(push
, NV50_3D(DEPTH_TEST_ENABLE
), 1);
1214 PUSH_DATA (push
, 0);
1215 BEGIN_NV04(push
, NV50_3D(DEPTH_BOUNDS_EN
), 1);
1216 PUSH_DATA (push
, 0);
1217 BEGIN_NV04(push
, NV50_3D(STENCIL_ENABLE
), 1);
1218 PUSH_DATA (push
, 0);
1219 BEGIN_NV04(push
, NV50_3D(ALPHA_TEST_ENABLE
), 1);
1220 PUSH_DATA (push
, 0);
1224 nv50_blitctx_pre_blit(struct nv50_blitctx
*ctx
,
1225 const struct pipe_blit_info
*info
)
1227 struct nv50_context
*nv50
= ctx
->nv50
;
1228 struct nv50_blitter
*blitter
= nv50
->screen
->blitter
;
1231 ctx
->saved
.fb
.width
= nv50
->framebuffer
.width
;
1232 ctx
->saved
.fb
.height
= nv50
->framebuffer
.height
;
1233 ctx
->saved
.fb
.nr_cbufs
= nv50
->framebuffer
.nr_cbufs
;
1234 ctx
->saved
.fb
.cbufs
[0] = nv50
->framebuffer
.cbufs
[0];
1235 ctx
->saved
.fb
.zsbuf
= nv50
->framebuffer
.zsbuf
;
1237 ctx
->saved
.rast
= nv50
->rast
;
1239 ctx
->saved
.vp
= nv50
->vertprog
;
1240 ctx
->saved
.gp
= nv50
->gmtyprog
;
1241 ctx
->saved
.fp
= nv50
->fragprog
;
1243 ctx
->saved
.min_samples
= nv50
->min_samples
;
1244 ctx
->saved
.window_rect
= nv50
->window_rect
;
1246 nv50
->rast
= &ctx
->rast
;
1248 nv50
->vertprog
= &blitter
->vp
;
1249 nv50
->gmtyprog
= NULL
;
1250 nv50
->fragprog
= ctx
->fp
;
1252 nv50
->window_rect
.rects
=
1253 MIN2(info
->num_window_rectangles
, NV50_MAX_WINDOW_RECTANGLES
);
1254 nv50
->window_rect
.inclusive
= info
->window_rectangle_include
;
1255 if (nv50
->window_rect
.rects
)
1256 memcpy(nv50
->window_rect
.rect
, info
->window_rectangles
,
1257 sizeof(struct pipe_scissor_state
) * nv50
->window_rect
.rects
);
1259 for (s
= 0; s
< 3; ++s
) {
1260 ctx
->saved
.num_textures
[s
] = nv50
->num_textures
[s
];
1261 ctx
->saved
.num_samplers
[s
] = nv50
->num_samplers
[s
];
1263 ctx
->saved
.texture
[0] = nv50
->textures
[2][0];
1264 ctx
->saved
.texture
[1] = nv50
->textures
[2][1];
1265 ctx
->saved
.sampler
[0] = nv50
->samplers
[2][0];
1266 ctx
->saved
.sampler
[1] = nv50
->samplers
[2][1];
1268 nv50
->samplers
[2][0] = &blitter
->sampler
[ctx
->filter
];
1269 nv50
->samplers
[2][1] = &blitter
->sampler
[ctx
->filter
];
1271 nv50
->num_samplers
[0] = nv50
->num_samplers
[1] = 0;
1272 nv50
->num_samplers
[2] = 2;
1274 nv50
->min_samples
= 1;
1276 ctx
->saved
.dirty_3d
= nv50
->dirty_3d
;
1278 nouveau_bufctx_reset(nv50
->bufctx_3d
, NV50_BIND_3D_FB
);
1279 nouveau_bufctx_reset(nv50
->bufctx_3d
, NV50_BIND_3D_TEXTURES
);
1282 NV50_NEW_3D_FRAMEBUFFER
| NV50_NEW_3D_MIN_SAMPLES
|
1283 NV50_NEW_3D_VERTPROG
| NV50_NEW_3D_FRAGPROG
| NV50_NEW_3D_GMTYPROG
|
1284 NV50_NEW_3D_TEXTURES
| NV50_NEW_3D_SAMPLERS
| NV50_NEW_3D_WINDOW_RECTS
;
1288 nv50_blitctx_post_blit(struct nv50_blitctx
*blit
)
1290 struct nv50_context
*nv50
= blit
->nv50
;
1293 pipe_surface_reference(&nv50
->framebuffer
.cbufs
[0], NULL
);
1295 nv50
->framebuffer
.width
= blit
->saved
.fb
.width
;
1296 nv50
->framebuffer
.height
= blit
->saved
.fb
.height
;
1297 nv50
->framebuffer
.nr_cbufs
= blit
->saved
.fb
.nr_cbufs
;
1298 nv50
->framebuffer
.cbufs
[0] = blit
->saved
.fb
.cbufs
[0];
1299 nv50
->framebuffer
.zsbuf
= blit
->saved
.fb
.zsbuf
;
1301 nv50
->rast
= blit
->saved
.rast
;
1303 nv50
->vertprog
= blit
->saved
.vp
;
1304 nv50
->gmtyprog
= blit
->saved
.gp
;
1305 nv50
->fragprog
= blit
->saved
.fp
;
1307 nv50
->min_samples
= blit
->saved
.min_samples
;
1308 nv50
->window_rect
= blit
->saved
.window_rect
;
1310 pipe_sampler_view_reference(&nv50
->textures
[2][0], NULL
);
1311 pipe_sampler_view_reference(&nv50
->textures
[2][1], NULL
);
1313 for (s
= 0; s
< 3; ++s
) {
1314 nv50
->num_textures
[s
] = blit
->saved
.num_textures
[s
];
1315 nv50
->num_samplers
[s
] = blit
->saved
.num_samplers
[s
];
1317 nv50
->textures
[2][0] = blit
->saved
.texture
[0];
1318 nv50
->textures
[2][1] = blit
->saved
.texture
[1];
1319 nv50
->samplers
[2][0] = blit
->saved
.sampler
[0];
1320 nv50
->samplers
[2][1] = blit
->saved
.sampler
[1];
1322 if (nv50
->cond_query
&& !blit
->render_condition_enable
)
1323 nv50
->base
.pipe
.render_condition(&nv50
->base
.pipe
, nv50
->cond_query
,
1324 nv50
->cond_cond
, nv50
->cond_mode
);
1326 nouveau_bufctx_reset(nv50
->bufctx_3d
, NV50_BIND_3D_FB
);
1327 nouveau_bufctx_reset(nv50
->bufctx_3d
, NV50_BIND_3D_TEXTURES
);
1329 nv50
->dirty_3d
= blit
->saved
.dirty_3d
|
1330 (NV50_NEW_3D_FRAMEBUFFER
| NV50_NEW_3D_SCISSOR
| NV50_NEW_3D_SAMPLE_MASK
|
1331 NV50_NEW_3D_RASTERIZER
| NV50_NEW_3D_ZSA
| NV50_NEW_3D_BLEND
|
1332 NV50_NEW_3D_TEXTURES
| NV50_NEW_3D_SAMPLERS
| NV50_NEW_3D_WINDOW_RECTS
|
1333 NV50_NEW_3D_VERTPROG
| NV50_NEW_3D_GMTYPROG
| NV50_NEW_3D_FRAGPROG
);
1334 nv50
->scissors_dirty
|= 1;
1336 nv50
->base
.pipe
.set_min_samples(&nv50
->base
.pipe
, blit
->saved
.min_samples
);
1341 nv50_blit_3d(struct nv50_context
*nv50
, const struct pipe_blit_info
*info
)
1343 struct nv50_blitctx
*blit
= nv50
->blit
;
1344 struct nouveau_pushbuf
*push
= nv50
->base
.pushbuf
;
1345 struct pipe_resource
*src
= info
->src
.resource
;
1346 struct pipe_resource
*dst
= info
->dst
.resource
;
1347 int32_t minx
, maxx
, miny
, maxy
;
1349 float x0
, x1
, y0
, y1
, z
;
1351 float x_range
, y_range
;
1354 blit
->mode
= nv50_blit_select_mode(info
);
1355 blit
->color_mask
= nv50_blit_derive_color_mask(info
);
1356 blit
->filter
= nv50_blit_get_filter(info
);
1357 blit
->render_condition_enable
= info
->render_condition_enable
;
1359 nv50_blit_select_fp(blit
, info
);
1360 nv50_blitctx_pre_blit(blit
, info
);
1362 nv50_blit_set_dst(blit
, dst
, info
->dst
.level
, -1, info
->dst
.format
);
1363 nv50_blit_set_src(blit
, src
, info
->src
.level
, -1, info
->src
.format
,
1366 nv50_blitctx_prepare_state(blit
);
1368 nv50_state_validate_3d(nv50
, ~0);
1370 x_range
= (float)info
->src
.box
.width
/ (float)info
->dst
.box
.width
;
1371 y_range
= (float)info
->src
.box
.height
/ (float)info
->dst
.box
.height
;
1373 tri_x
= 16384 << nv50_miptree(dst
)->ms_x
;
1374 tri_y
= 16384 << nv50_miptree(dst
)->ms_y
;
1376 x0
= (float)info
->src
.box
.x
- x_range
* (float)info
->dst
.box
.x
;
1377 y0
= (float)info
->src
.box
.y
- y_range
* (float)info
->dst
.box
.y
;
1379 x1
= x0
+ tri_x
* x_range
;
1380 y1
= y0
+ tri_y
* y_range
;
1382 x0
*= (float)(1 << nv50_miptree(src
)->ms_x
);
1383 x1
*= (float)(1 << nv50_miptree(src
)->ms_x
);
1384 y0
*= (float)(1 << nv50_miptree(src
)->ms_y
);
1385 y1
*= (float)(1 << nv50_miptree(src
)->ms_y
);
1387 /* XXX: multiply by 6 for cube arrays ? */
1388 dz
= (float)info
->src
.box
.depth
/ (float)info
->dst
.box
.depth
;
1389 z
= (float)info
->src
.box
.z
;
1390 if (nv50_miptree(src
)->layout_3d
)
1393 if (src
->last_level
> 0) {
1394 /* If there are mip maps, GPU always assumes normalized coordinates. */
1395 const unsigned l
= info
->src
.level
;
1396 const float fh
= u_minify(src
->width0
<< nv50_miptree(src
)->ms_x
, l
);
1397 const float fv
= u_minify(src
->height0
<< nv50_miptree(src
)->ms_y
, l
);
1402 if (nv50_miptree(src
)->layout_3d
) {
1403 z
/= u_minify(src
->depth0
, l
);
1404 dz
/= u_minify(src
->depth0
, l
);
1408 BEGIN_NV04(push
, NV50_3D(VIEWPORT_TRANSFORM_EN
), 1);
1409 PUSH_DATA (push
, 0);
1410 BEGIN_NV04(push
, NV50_3D(VIEW_VOLUME_CLIP_CTRL
), 1);
1411 PUSH_DATA (push
, 0x1);
1413 /* Draw a large triangle in screen coordinates covering the whole
1414 * render target, with scissors defining the destination region.
1415 * The vertex is supplied with non-normalized texture coordinates
1416 * arranged in a way to yield the desired offset and scale.
1419 minx
= info
->dst
.box
.x
;
1420 maxx
= info
->dst
.box
.x
+ info
->dst
.box
.width
;
1421 miny
= info
->dst
.box
.y
;
1422 maxy
= info
->dst
.box
.y
+ info
->dst
.box
.height
;
1423 if (info
->scissor_enable
) {
1424 minx
= MAX2(minx
, info
->scissor
.minx
);
1425 maxx
= MIN2(maxx
, info
->scissor
.maxx
);
1426 miny
= MAX2(miny
, info
->scissor
.miny
);
1427 maxy
= MIN2(maxy
, info
->scissor
.maxy
);
1429 BEGIN_NV04(push
, NV50_3D(SCISSOR_HORIZ(0)), 2);
1430 PUSH_DATA (push
, (maxx
<< 16) | minx
);
1431 PUSH_DATA (push
, (maxy
<< 16) | miny
);
1433 for (i
= 0; i
< info
->dst
.box
.depth
; ++i
, z
+= dz
) {
1434 if (info
->dst
.box
.z
+ i
) {
1435 BEGIN_NV04(push
, NV50_3D(LAYER
), 1);
1436 PUSH_DATA (push
, info
->dst
.box
.z
+ i
);
1438 PUSH_SPACE(push
, 32);
1439 BEGIN_NV04(push
, NV50_3D(VERTEX_BEGIN_GL
), 1);
1440 PUSH_DATA (push
, NV50_3D_VERTEX_BEGIN_GL_PRIMITIVE_TRIANGLES
);
1441 BEGIN_NV04(push
, NV50_3D(VTX_ATTR_3F_X(1)), 3);
1442 PUSH_DATAf(push
, x0
);
1443 PUSH_DATAf(push
, y0
);
1444 PUSH_DATAf(push
, z
);
1445 BEGIN_NV04(push
, NV50_3D(VTX_ATTR_2F_X(0)), 2);
1446 PUSH_DATAf(push
, 0.0f
);
1447 PUSH_DATAf(push
, 0.0f
);
1448 BEGIN_NV04(push
, NV50_3D(VTX_ATTR_3F_X(1)), 3);
1449 PUSH_DATAf(push
, x1
);
1450 PUSH_DATAf(push
, y0
);
1451 PUSH_DATAf(push
, z
);
1452 BEGIN_NV04(push
, NV50_3D(VTX_ATTR_2F_X(0)), 2);
1453 PUSH_DATAf(push
, tri_x
);
1454 PUSH_DATAf(push
, 0.0f
);
1455 BEGIN_NV04(push
, NV50_3D(VTX_ATTR_3F_X(1)), 3);
1456 PUSH_DATAf(push
, x0
);
1457 PUSH_DATAf(push
, y1
);
1458 PUSH_DATAf(push
, z
);
1459 BEGIN_NV04(push
, NV50_3D(VTX_ATTR_2F_X(0)), 2);
1460 PUSH_DATAf(push
, 0.0f
);
1461 PUSH_DATAf(push
, tri_y
);
1462 BEGIN_NV04(push
, NV50_3D(VERTEX_END_GL
), 1);
1463 PUSH_DATA (push
, 0);
1465 if (info
->dst
.box
.z
+ info
->dst
.box
.depth
- 1) {
1466 BEGIN_NV04(push
, NV50_3D(LAYER
), 1);
1467 PUSH_DATA (push
, 0);
1470 /* re-enable normally constant state */
1472 BEGIN_NV04(push
, NV50_3D(VIEWPORT_TRANSFORM_EN
), 1);
1473 PUSH_DATA (push
, 1);
1475 nv50_blitctx_post_blit(blit
);
1479 nv50_blit_eng2d(struct nv50_context
*nv50
, const struct pipe_blit_info
*info
)
1481 struct nouveau_pushbuf
*push
= nv50
->base
.pushbuf
;
1482 struct nv50_miptree
*dst
= nv50_miptree(info
->dst
.resource
);
1483 struct nv50_miptree
*src
= nv50_miptree(info
->src
.resource
);
1484 const int32_t srcx_adj
= info
->src
.box
.width
< 0 ? -1 : 0;
1485 const int32_t srcy_adj
= info
->src
.box
.height
< 0 ? -1 : 0;
1486 const int32_t dz
= info
->dst
.box
.z
;
1487 const int32_t sz
= info
->src
.box
.z
;
1488 uint32_t dstw
, dsth
;
1491 int64_t du_dx
, dv_dy
;
1494 uint32_t mask
= nv50_blit_eng2d_get_mask(info
);
1497 mode
= nv50_blit_get_filter(info
) ?
1498 NV50_2D_BLIT_CONTROL_FILTER_BILINEAR
:
1499 NV50_2D_BLIT_CONTROL_FILTER_POINT_SAMPLE
;
1500 mode
|= (src
->base
.base
.nr_samples
> dst
->base
.base
.nr_samples
) ?
1501 NV50_2D_BLIT_CONTROL_ORIGIN_CORNER
: NV50_2D_BLIT_CONTROL_ORIGIN_CENTER
;
1503 du_dx
= ((int64_t)info
->src
.box
.width
<< 32) / info
->dst
.box
.width
;
1504 dv_dy
= ((int64_t)info
->src
.box
.height
<< 32) / info
->dst
.box
.height
;
1506 b
= info
->dst
.format
== info
->src
.format
;
1507 nv50_2d_texture_set(push
, 1, dst
, info
->dst
.level
, dz
, info
->dst
.format
, b
);
1508 nv50_2d_texture_set(push
, 0, src
, info
->src
.level
, sz
, info
->src
.format
, b
);
1510 if (info
->scissor_enable
) {
1511 BEGIN_NV04(push
, NV50_2D(CLIP_X
), 5);
1512 PUSH_DATA (push
, info
->scissor
.minx
<< dst
->ms_x
);
1513 PUSH_DATA (push
, info
->scissor
.miny
<< dst
->ms_y
);
1514 PUSH_DATA (push
, (info
->scissor
.maxx
- info
->scissor
.minx
) << dst
->ms_x
);
1515 PUSH_DATA (push
, (info
->scissor
.maxy
- info
->scissor
.miny
) << dst
->ms_y
);
1516 PUSH_DATA (push
, 1); /* enable */
1519 if (nv50
->cond_query
&& info
->render_condition_enable
) {
1520 BEGIN_NV04(push
, NV50_2D(COND_MODE
), 1);
1521 PUSH_DATA (push
, nv50
->cond_condmode
);
1524 if (mask
!= 0xffffffff) {
1525 BEGIN_NV04(push
, NV50_2D(ROP
), 1);
1526 PUSH_DATA (push
, 0xca); /* DPSDxax */
1527 BEGIN_NV04(push
, NV50_2D(PATTERN_COLOR_FORMAT
), 1);
1528 PUSH_DATA (push
, NV50_2D_PATTERN_COLOR_FORMAT_A8R8G8B8
);
1529 BEGIN_NV04(push
, NV50_2D(PATTERN_BITMAP_COLOR(0)), 4);
1530 PUSH_DATA (push
, 0x00000000);
1531 PUSH_DATA (push
, mask
);
1532 PUSH_DATA (push
, 0xffffffff);
1533 PUSH_DATA (push
, 0xffffffff);
1534 BEGIN_NV04(push
, NV50_2D(OPERATION
), 1);
1535 PUSH_DATA (push
, NV50_2D_OPERATION_ROP
);
1537 if (info
->src
.format
!= info
->dst
.format
) {
1538 if (info
->src
.format
== PIPE_FORMAT_R8_UNORM
||
1539 info
->src
.format
== PIPE_FORMAT_R16_UNORM
||
1540 info
->src
.format
== PIPE_FORMAT_R16_FLOAT
||
1541 info
->src
.format
== PIPE_FORMAT_R32_FLOAT
) {
1542 mask
= 0xffff0000; /* also makes condition for OPERATION reset true */
1543 BEGIN_NV04(push
, NV50_2D(BETA4
), 2);
1544 PUSH_DATA (push
, mask
);
1545 PUSH_DATA (push
, NV50_2D_OPERATION_SRCCOPY_PREMULT
);
1549 if (src
->ms_x
> dst
->ms_x
|| src
->ms_y
> dst
->ms_y
) {
1550 /* ms_x is always >= ms_y */
1551 du_dx
<<= src
->ms_x
- dst
->ms_x
;
1552 dv_dy
<<= src
->ms_y
- dst
->ms_y
;
1554 du_dx
>>= dst
->ms_x
- src
->ms_x
;
1555 dv_dy
>>= dst
->ms_y
- src
->ms_y
;
1558 srcx
= (int64_t)(info
->src
.box
.x
+ srcx_adj
) << (src
->ms_x
+ 32);
1559 srcy
= (int64_t)(info
->src
.box
.y
+ srcy_adj
) << (src
->ms_y
+ 32);
1561 if (src
->base
.base
.nr_samples
> dst
->base
.base
.nr_samples
) {
1562 /* center src coorinates for proper MS resolve filtering */
1563 srcx
+= (int64_t)1 << (src
->ms_x
+ 31);
1564 srcy
+= (int64_t)1 << (src
->ms_y
+ 31);
1567 dstx
= info
->dst
.box
.x
<< dst
->ms_x
;
1568 dsty
= info
->dst
.box
.y
<< dst
->ms_y
;
1570 dstw
= info
->dst
.box
.width
<< dst
->ms_x
;
1571 dsth
= info
->dst
.box
.height
<< dst
->ms_y
;
1575 srcx
-= du_dx
* dstx
;
1580 srcy
-= dv_dy
* dsty
;
1584 BEGIN_NV04(push
, NV50_2D(BLIT_CONTROL
), 1);
1585 PUSH_DATA (push
, mode
);
1586 BEGIN_NV04(push
, NV50_2D(BLIT_DST_X
), 4);
1587 PUSH_DATA (push
, dstx
);
1588 PUSH_DATA (push
, dsty
);
1589 PUSH_DATA (push
, dstw
);
1590 PUSH_DATA (push
, dsth
);
1591 BEGIN_NV04(push
, NV50_2D(BLIT_DU_DX_FRACT
), 4);
1592 PUSH_DATA (push
, du_dx
);
1593 PUSH_DATA (push
, du_dx
>> 32);
1594 PUSH_DATA (push
, dv_dy
);
1595 PUSH_DATA (push
, dv_dy
>> 32);
1597 BCTX_REFN(nv50
->bufctx
, 2D
, &dst
->base
, WR
);
1598 BCTX_REFN(nv50
->bufctx
, 2D
, &src
->base
, RD
);
1599 nouveau_pushbuf_bufctx(nv50
->base
.pushbuf
, nv50
->bufctx
);
1600 if (nouveau_pushbuf_validate(nv50
->base
.pushbuf
))
1603 for (i
= 0; i
< info
->dst
.box
.depth
; ++i
) {
1605 /* no scaling in z-direction possible for eng2d blits */
1606 if (dst
->layout_3d
) {
1607 BEGIN_NV04(push
, NV50_2D(DST_LAYER
), 1);
1608 PUSH_DATA (push
, info
->dst
.box
.z
+ i
);
1610 const unsigned z
= info
->dst
.box
.z
+ i
;
1611 const uint64_t address
= dst
->base
.address
+
1612 dst
->level
[info
->dst
.level
].offset
+
1613 z
* dst
->layer_stride
;
1614 BEGIN_NV04(push
, NV50_2D(DST_ADDRESS_HIGH
), 2);
1615 PUSH_DATAh(push
, address
);
1616 PUSH_DATA (push
, address
);
1618 if (src
->layout_3d
) {
1619 /* not possible because of depth tiling */
1622 const unsigned z
= info
->src
.box
.z
+ i
;
1623 const uint64_t address
= src
->base
.address
+
1624 src
->level
[info
->src
.level
].offset
+
1625 z
* src
->layer_stride
;
1626 BEGIN_NV04(push
, NV50_2D(SRC_ADDRESS_HIGH
), 2);
1627 PUSH_DATAh(push
, address
);
1628 PUSH_DATA (push
, address
);
1630 BEGIN_NV04(push
, NV50_2D(BLIT_SRC_Y_INT
), 1); /* trigger */
1631 PUSH_DATA (push
, srcy
>> 32);
1633 BEGIN_NV04(push
, NV50_2D(BLIT_SRC_X_FRACT
), 4);
1634 PUSH_DATA (push
, srcx
);
1635 PUSH_DATA (push
, srcx
>> 32);
1636 PUSH_DATA (push
, srcy
);
1637 PUSH_DATA (push
, srcy
>> 32);
1640 nv50_bufctx_fence(nv50
->bufctx
, false);
1642 nouveau_bufctx_reset(nv50
->bufctx
, NV50_BIND_2D
);
1644 if (info
->scissor_enable
) {
1645 BEGIN_NV04(push
, NV50_2D(CLIP_ENABLE
), 1);
1646 PUSH_DATA (push
, 0);
1648 if (mask
!= 0xffffffff) {
1649 BEGIN_NV04(push
, NV50_2D(OPERATION
), 1);
1650 PUSH_DATA (push
, NV50_2D_OPERATION_SRCCOPY
);
1652 if (nv50
->cond_query
&& info
->render_condition_enable
) {
1653 BEGIN_NV04(push
, NV50_2D(COND_MODE
), 1);
1654 PUSH_DATA (push
, NV50_2D_COND_MODE_ALWAYS
);
1659 nv50_blit(struct pipe_context
*pipe
, const struct pipe_blit_info
*info
)
1661 struct nv50_context
*nv50
= nv50_context(pipe
);
1662 struct nouveau_pushbuf
*push
= nv50
->base
.pushbuf
;
1665 if (util_format_is_depth_or_stencil(info
->dst
.resource
->format
)) {
1666 if (!(info
->mask
& PIPE_MASK_ZS
))
1668 if (info
->dst
.resource
->format
== PIPE_FORMAT_Z32_FLOAT
||
1669 info
->dst
.resource
->format
== PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
)
1671 if (info
->filter
!= PIPE_TEX_FILTER_NEAREST
)
1674 if (!(info
->mask
& PIPE_MASK_RGBA
))
1676 if (info
->mask
!= PIPE_MASK_RGBA
)
1680 if (nv50_miptree(info
->src
.resource
)->layout_3d
) {
1683 if (info
->src
.box
.depth
!= info
->dst
.box
.depth
) {
1685 debug_printf("blit: cannot filter array or cube textures in z direction");
1688 if (!eng3d
&& info
->dst
.format
!= info
->src
.format
) {
1689 if (!nv50_2d_dst_format_faithful(info
->dst
.format
) ||
1690 !nv50_2d_src_format_faithful(info
->src
.format
)) {
1693 if (!nv50_2d_src_format_faithful(info
->src
.format
)) {
1694 if (!util_format_is_luminance(info
->src
.format
)) {
1695 if (util_format_is_intensity(info
->src
.format
))
1698 if (!nv50_2d_dst_format_ops_supported(info
->dst
.format
))
1701 eng3d
= !nv50_2d_format_supported(info
->src
.format
);
1704 if (util_format_is_luminance_alpha(info
->src
.format
))
1708 if (info
->src
.resource
->nr_samples
== 8 &&
1709 info
->dst
.resource
->nr_samples
<= 1)
1712 if (info
->num_window_rectangles
> 0 || info
->window_rectangle_include
)
1715 /* FIXME: can't make this work with eng2d anymore */
1716 if ((info
->src
.resource
->nr_samples
| 1) !=
1717 (info
->dst
.resource
->nr_samples
| 1))
1720 /* FIXME: find correct src coordinate adjustments */
1721 if ((info
->src
.box
.width
!= info
->dst
.box
.width
&&
1722 info
->src
.box
.width
!= -info
->dst
.box
.width
) ||
1723 (info
->src
.box
.height
!= info
->dst
.box
.height
&&
1724 info
->src
.box
.height
!= -info
->dst
.box
.height
))
1727 if (nv50
->screen
->num_occlusion_queries_active
) {
1728 BEGIN_NV04(push
, NV50_3D(SAMPLECNT_ENABLE
), 1);
1729 PUSH_DATA (push
, 0);
1733 nv50_blit_eng2d(nv50
, info
);
1735 nv50_blit_3d(nv50
, info
);
1737 if (nv50
->screen
->num_occlusion_queries_active
) {
1738 BEGIN_NV04(push
, NV50_3D(SAMPLECNT_ENABLE
), 1);
1739 PUSH_DATA (push
, 1);
1744 nv50_flush_resource(struct pipe_context
*ctx
,
1745 struct pipe_resource
*resource
)
1750 nv50_blitter_create(struct nv50_screen
*screen
)
1752 screen
->blitter
= CALLOC_STRUCT(nv50_blitter
);
1753 if (!screen
->blitter
) {
1754 NOUVEAU_ERR("failed to allocate blitter struct\n");
1758 (void) mtx_init(&screen
->blitter
->mutex
, mtx_plain
);
1760 nv50_blitter_make_vp(screen
->blitter
);
1761 nv50_blitter_make_sampler(screen
->blitter
);
1767 nv50_blitter_destroy(struct nv50_screen
*screen
)
1769 struct nv50_blitter
*blitter
= screen
->blitter
;
1772 for (i
= 0; i
< NV50_BLIT_MAX_TEXTURE_TYPES
; ++i
) {
1773 for (m
= 0; m
< NV50_BLIT_MODES
; ++m
) {
1774 struct nv50_program
*prog
= blitter
->fp
[i
][m
];
1776 nv50_program_destroy(NULL
, prog
);
1777 FREE((void *)prog
->pipe
.tokens
);
1783 mtx_destroy(&blitter
->mutex
);
1788 nv50_blitctx_create(struct nv50_context
*nv50
)
1790 nv50
->blit
= CALLOC_STRUCT(nv50_blitctx
);
1792 NOUVEAU_ERR("failed to allocate blit context\n");
1796 nv50
->blit
->nv50
= nv50
;
1798 nv50
->blit
->rast
.pipe
.half_pixel_center
= 1;
1804 nv50_init_surface_functions(struct nv50_context
*nv50
)
1806 struct pipe_context
*pipe
= &nv50
->base
.pipe
;
1808 pipe
->resource_copy_region
= nv50_resource_copy_region
;
1809 pipe
->blit
= nv50_blit
;
1810 pipe
->flush_resource
= nv50_flush_resource
;
1811 pipe
->clear_texture
= nv50_clear_texture
;
1812 pipe
->clear_render_target
= nv50_clear_render_target
;
1813 pipe
->clear_depth_stencil
= nv50_clear_depth_stencil
;
1814 pipe
->clear_buffer
= nv50_clear_buffer
;