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_surface.h"
32 #include "os/os_thread.h"
34 #include "nvc0/nvc0_context.h"
35 #include "nvc0/nvc0_resource.h"
37 #include "nv50/nv50_defs.xml.h"
38 #include "nv50/nv50_texture.xml.h"
40 /* these are used in nv50_blit.h */
41 #define NV50_ENG2D_SUPPORTED_FORMATS 0xff9ccfe1cce3ccc9ULL
42 #define NV50_ENG2D_NOCONVERT_FORMATS 0x009cc02000000000ULL
43 #define NV50_ENG2D_LUMINANCE_FORMATS 0x001cc02000000000ULL
44 #define NV50_ENG2D_INTENSITY_FORMATS 0x0080000000000000ULL
45 #define NV50_ENG2D_OPERATION_FORMATS 0x060001c000638000ULL
47 #define NOUVEAU_DRIVER 0xc0
48 #include "nv50/nv50_blit.h"
51 nvc0_2d_format(enum pipe_format format
, bool dst
, bool dst_src_equal
)
53 uint8_t id
= nvc0_format_table
[format
].rt
;
55 /* A8_UNORM is treated as I8_UNORM as far as the 2D engine is concerned. */
56 if (!dst
&& unlikely(format
== PIPE_FORMAT_I8_UNORM
) && !dst_src_equal
)
57 return NV50_SURFACE_FORMAT_A8_UNORM
;
59 /* Hardware values for color formats range from 0xc0 to 0xff,
60 * but the 2D engine doesn't support all of them.
62 if (nv50_2d_format_supported(format
))
64 assert(dst_src_equal
);
66 switch (util_format_get_blocksize(format
)) {
68 return NV50_SURFACE_FORMAT_R8_UNORM
;
70 return NV50_SURFACE_FORMAT_RG8_UNORM
;
72 return NV50_SURFACE_FORMAT_BGRA8_UNORM
;
74 return NV50_SURFACE_FORMAT_RGBA16_UNORM
;
76 return NV50_SURFACE_FORMAT_RGBA32_FLOAT
;
84 nvc0_2d_texture_set(struct nouveau_pushbuf
*push
, bool dst
,
85 struct nv50_miptree
*mt
, unsigned level
, unsigned layer
,
86 enum pipe_format pformat
, bool dst_src_pformat_equal
)
88 struct nouveau_bo
*bo
= mt
->base
.bo
;
89 uint32_t width
, height
, depth
;
91 uint32_t mthd
= dst
? NV50_2D_DST_FORMAT
: NV50_2D_SRC_FORMAT
;
92 uint32_t offset
= mt
->level
[level
].offset
;
94 format
= nvc0_2d_format(pformat
, dst
, dst_src_pformat_equal
);
96 NOUVEAU_ERR("invalid/unsupported surface format: %s\n",
97 util_format_name(pformat
));
101 width
= u_minify(mt
->base
.base
.width0
, level
) << mt
->ms_x
;
102 height
= u_minify(mt
->base
.base
.height0
, level
) << mt
->ms_y
;
103 depth
= u_minify(mt
->base
.base
.depth0
, level
);
105 /* layer has to be < depth, and depth > tile depth / 2 */
107 if (!mt
->layout_3d
) {
108 offset
+= mt
->layer_stride
* layer
;
113 offset
+= nvc0_mt_zslice_offset(mt
, level
, layer
);
117 if (!nouveau_bo_memtype(bo
)) {
118 BEGIN_NVC0(push
, SUBC_2D(mthd
), 2);
119 PUSH_DATA (push
, format
);
121 BEGIN_NVC0(push
, SUBC_2D(mthd
+ 0x14), 5);
122 PUSH_DATA (push
, mt
->level
[level
].pitch
);
123 PUSH_DATA (push
, width
);
124 PUSH_DATA (push
, height
);
125 PUSH_DATAh(push
, bo
->offset
+ offset
);
126 PUSH_DATA (push
, bo
->offset
+ offset
);
128 BEGIN_NVC0(push
, SUBC_2D(mthd
), 5);
129 PUSH_DATA (push
, format
);
131 PUSH_DATA (push
, mt
->level
[level
].tile_mode
);
132 PUSH_DATA (push
, depth
);
133 PUSH_DATA (push
, layer
);
134 BEGIN_NVC0(push
, SUBC_2D(mthd
+ 0x18), 4);
135 PUSH_DATA (push
, width
);
136 PUSH_DATA (push
, height
);
137 PUSH_DATAh(push
, bo
->offset
+ offset
);
138 PUSH_DATA (push
, bo
->offset
+ offset
);
143 BEGIN_NVC0(push
, SUBC_2D(NVC0_2D_CLIP_X
), 4);
146 PUSH_DATA (push
, width
);
147 PUSH_DATA (push
, height
);
154 nvc0_2d_texture_do_copy(struct nouveau_pushbuf
*push
,
155 struct nv50_miptree
*dst
, unsigned dst_level
,
156 unsigned dx
, unsigned dy
, unsigned dz
,
157 struct nv50_miptree
*src
, unsigned src_level
,
158 unsigned sx
, unsigned sy
, unsigned sz
,
159 unsigned w
, unsigned h
)
161 const enum pipe_format dfmt
= dst
->base
.base
.format
;
162 const enum pipe_format sfmt
= src
->base
.base
.format
;
164 bool eqfmt
= dfmt
== sfmt
;
166 if (!PUSH_SPACE(push
, 2 * 16 + 32))
169 ret
= nvc0_2d_texture_set(push
, true, dst
, dst_level
, dz
, dfmt
, eqfmt
);
173 ret
= nvc0_2d_texture_set(push
, false, src
, src_level
, sz
, sfmt
, eqfmt
);
177 IMMED_NVC0(push
, NVC0_2D(BLIT_CONTROL
), 0x00);
178 BEGIN_NVC0(push
, NVC0_2D(BLIT_DST_X
), 4);
179 PUSH_DATA (push
, dx
<< dst
->ms_x
);
180 PUSH_DATA (push
, dy
<< dst
->ms_y
);
181 PUSH_DATA (push
, w
<< dst
->ms_x
);
182 PUSH_DATA (push
, h
<< dst
->ms_y
);
183 BEGIN_NVC0(push
, NVC0_2D(BLIT_DU_DX_FRACT
), 4);
188 BEGIN_NVC0(push
, NVC0_2D(BLIT_SRC_X_FRACT
), 4);
190 PUSH_DATA (push
, sx
<< src
->ms_x
);
192 PUSH_DATA (push
, sy
<< src
->ms_y
);
198 nvc0_resource_copy_region(struct pipe_context
*pipe
,
199 struct pipe_resource
*dst
, unsigned dst_level
,
200 unsigned dstx
, unsigned dsty
, unsigned dstz
,
201 struct pipe_resource
*src
, unsigned src_level
,
202 const struct pipe_box
*src_box
)
204 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
207 unsigned dst_layer
= dstz
, src_layer
= src_box
->z
;
209 if (dst
->target
== PIPE_BUFFER
&& src
->target
== PIPE_BUFFER
) {
210 nouveau_copy_buffer(&nvc0
->base
,
211 nv04_resource(dst
), dstx
,
212 nv04_resource(src
), src_box
->x
, src_box
->width
);
213 NOUVEAU_DRV_STAT(&nvc0
->screen
->base
, buf_copy_bytes
, src_box
->width
);
216 NOUVEAU_DRV_STAT(&nvc0
->screen
->base
, tex_copy_count
, 1);
218 /* 0 and 1 are equal, only supporting 0/1, 2, 4 and 8 */
219 assert((src
->nr_samples
| 1) == (dst
->nr_samples
| 1));
221 m2mf
= (src
->format
== dst
->format
) ||
222 (util_format_get_blocksizebits(src
->format
) ==
223 util_format_get_blocksizebits(dst
->format
));
225 nv04_resource(dst
)->status
|= NOUVEAU_BUFFER_STATUS_GPU_WRITING
;
228 struct nv50_miptree
*src_mt
= nv50_miptree(src
);
229 struct nv50_miptree
*dst_mt
= nv50_miptree(dst
);
230 struct nv50_m2mf_rect drect
, srect
;
232 unsigned nx
= util_format_get_nblocksx(src
->format
, src_box
->width
)
234 unsigned ny
= util_format_get_nblocksy(src
->format
, src_box
->height
)
237 nv50_m2mf_rect_setup(&drect
, dst
, dst_level
, dstx
, dsty
, dstz
);
238 nv50_m2mf_rect_setup(&srect
, src
, src_level
,
239 src_box
->x
, src_box
->y
, src_box
->z
);
241 for (i
= 0; i
< src_box
->depth
; ++i
) {
242 nvc0
->m2mf_copy_rect(nvc0
, &drect
, &srect
, nx
, ny
);
244 if (dst_mt
->layout_3d
)
247 drect
.base
+= dst_mt
->layer_stride
;
249 if (src_mt
->layout_3d
)
252 srect
.base
+= src_mt
->layer_stride
;
257 assert(nv50_2d_dst_format_faithful(dst
->format
));
258 assert(nv50_2d_src_format_faithful(src
->format
));
260 BCTX_REFN(nvc0
->bufctx
, 2D
, nv04_resource(src
), RD
);
261 BCTX_REFN(nvc0
->bufctx
, 2D
, nv04_resource(dst
), WR
);
262 nouveau_pushbuf_bufctx(nvc0
->base
.pushbuf
, nvc0
->bufctx
);
263 nouveau_pushbuf_validate(nvc0
->base
.pushbuf
);
265 for (; dst_layer
< dstz
+ src_box
->depth
; ++dst_layer
, ++src_layer
) {
266 ret
= nvc0_2d_texture_do_copy(nvc0
->base
.pushbuf
,
267 nv50_miptree(dst
), dst_level
,
268 dstx
, dsty
, dst_layer
,
269 nv50_miptree(src
), src_level
,
270 src_box
->x
, src_box
->y
, src_layer
,
271 src_box
->width
, src_box
->height
);
275 nouveau_bufctx_reset(nvc0
->bufctx
, 0);
279 nvc0_clear_render_target(struct pipe_context
*pipe
,
280 struct pipe_surface
*dst
,
281 const union pipe_color_union
*color
,
282 unsigned dstx
, unsigned dsty
,
283 unsigned width
, unsigned height
)
285 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
286 struct nouveau_pushbuf
*push
= nvc0
->base
.pushbuf
;
287 struct nv50_surface
*sf
= nv50_surface(dst
);
288 struct nv04_resource
*res
= nv04_resource(sf
->base
.texture
);
291 assert(dst
->texture
->target
!= PIPE_BUFFER
);
293 if (!PUSH_SPACE(push
, 32 + sf
->depth
))
296 PUSH_REFN (push
, res
->bo
, res
->domain
| NOUVEAU_BO_WR
);
298 BEGIN_NVC0(push
, NVC0_3D(CLEAR_COLOR(0)), 4);
299 PUSH_DATAf(push
, color
->f
[0]);
300 PUSH_DATAf(push
, color
->f
[1]);
301 PUSH_DATAf(push
, color
->f
[2]);
302 PUSH_DATAf(push
, color
->f
[3]);
304 BEGIN_NVC0(push
, NVC0_3D(SCREEN_SCISSOR_HORIZ
), 2);
305 PUSH_DATA (push
, ( width
<< 16) | dstx
);
306 PUSH_DATA (push
, (height
<< 16) | dsty
);
308 BEGIN_NVC0(push
, NVC0_3D(RT_CONTROL
), 1);
310 BEGIN_NVC0(push
, NVC0_3D(RT_ADDRESS_HIGH(0)), 9);
311 PUSH_DATAh(push
, res
->address
+ sf
->offset
);
312 PUSH_DATA (push
, res
->address
+ sf
->offset
);
313 if (likely(nouveau_bo_memtype(res
->bo
))) {
314 struct nv50_miptree
*mt
= nv50_miptree(dst
->texture
);
316 PUSH_DATA(push
, sf
->width
);
317 PUSH_DATA(push
, sf
->height
);
318 PUSH_DATA(push
, nvc0_format_table
[dst
->format
].rt
);
319 PUSH_DATA(push
, (mt
->layout_3d
<< 16) |
320 mt
->level
[sf
->base
.u
.tex
.level
].tile_mode
);
321 PUSH_DATA(push
, dst
->u
.tex
.first_layer
+ sf
->depth
);
322 PUSH_DATA(push
, mt
->layer_stride
>> 2);
323 PUSH_DATA(push
, dst
->u
.tex
.first_layer
);
324 IMMED_NVC0(push
, NVC0_3D(MULTISAMPLE_MODE
), mt
->ms_mode
);
326 if (res
->base
.target
== PIPE_BUFFER
) {
327 PUSH_DATA(push
, 262144);
330 PUSH_DATA(push
, nv50_miptree(&res
->base
)->level
[0].pitch
);
331 PUSH_DATA(push
, sf
->height
);
333 PUSH_DATA(push
, nvc0_format_table
[sf
->base
.format
].rt
);
334 PUSH_DATA(push
, 1 << 12);
339 IMMED_NVC0(push
, NVC0_3D(ZETA_ENABLE
), 0);
340 IMMED_NVC0(push
, NVC0_3D(MULTISAMPLE_MODE
), 0);
342 /* tiled textures don't have to be fenced, they're not mapped directly */
343 nvc0_resource_fence(res
, NOUVEAU_BO_WR
);
346 IMMED_NVC0(push
, NVC0_3D(COND_MODE
), NVC0_3D_COND_MODE_ALWAYS
);
348 BEGIN_NIC0(push
, NVC0_3D(CLEAR_BUFFERS
), sf
->depth
);
349 for (z
= 0; z
< sf
->depth
; ++z
) {
350 PUSH_DATA (push
, 0x3c |
351 (z
<< NVC0_3D_CLEAR_BUFFERS_LAYER__SHIFT
));
354 IMMED_NVC0(push
, NVC0_3D(COND_MODE
), nvc0
->cond_condmode
);
356 nvc0
->dirty
|= NVC0_NEW_FRAMEBUFFER
;
360 nvc0_clear_buffer_cpu(struct pipe_context
*pipe
,
361 struct pipe_resource
*res
,
362 unsigned offset
, unsigned size
,
363 const void *data
, int data_size
)
365 struct nv04_resource
*buf
= nv04_resource(res
);
366 struct pipe_transfer
*pt
;
368 unsigned elements
, i
;
370 elements
= size
/ data_size
;
372 u_box_1d(offset
, size
, &box
);
374 uint8_t *map
= buf
->vtbl
->transfer_map(pipe
, res
, 0, PIPE_TRANSFER_WRITE
,
377 for (i
= 0; i
< elements
; ++i
)
378 memcpy(&map
[i
*data_size
], data
, data_size
);
380 buf
->vtbl
->transfer_unmap(pipe
, pt
);
384 nvc0_clear_buffer(struct pipe_context
*pipe
,
385 struct pipe_resource
*res
,
386 unsigned offset
, unsigned size
,
387 const void *data
, int data_size
)
389 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
390 struct nouveau_pushbuf
*push
= nvc0
->base
.pushbuf
;
391 struct nv04_resource
*buf
= nv04_resource(res
);
392 union pipe_color_union color
;
393 enum pipe_format dst_fmt
;
394 unsigned width
, height
, elements
;
396 assert(res
->target
== PIPE_BUFFER
);
397 assert(nouveau_bo_memtype(buf
->bo
) == 0);
401 dst_fmt
= PIPE_FORMAT_R32G32B32A32_UINT
;
402 memcpy(&color
.ui
, data
, 16);
405 /* This doesn't work, RGB32 is not a valid RT format.
406 * dst_fmt = PIPE_FORMAT_R32G32B32_UINT;
407 * memcpy(&color.ui, data, 12);
408 * memset(&color.ui[3], 0, 4);
412 dst_fmt
= PIPE_FORMAT_R32G32_UINT
;
413 memcpy(&color
.ui
, data
, 8);
414 memset(&color
.ui
[2], 0, 8);
417 dst_fmt
= PIPE_FORMAT_R32_UINT
;
418 memcpy(&color
.ui
, data
, 4);
419 memset(&color
.ui
[1], 0, 12);
422 dst_fmt
= PIPE_FORMAT_R16_UINT
;
423 color
.ui
[0] = util_cpu_to_le32(
424 util_le16_to_cpu(*(unsigned short *)data
));
425 memset(&color
.ui
[1], 0, 12);
428 dst_fmt
= PIPE_FORMAT_R8_UINT
;
429 color
.ui
[0] = util_cpu_to_le32(*(unsigned char *)data
);
430 memset(&color
.ui
[1], 0, 12);
433 assert(!"Unsupported element size");
437 assert(size
% data_size
== 0);
439 if (data_size
== 12) {
440 /* TODO: Find a way to do this with the GPU! */
441 nvc0_clear_buffer_cpu(pipe
, res
, offset
, size
, data
, data_size
);
445 elements
= size
/ data_size
;
446 height
= (elements
+ 16383) / 16384;
447 width
= elements
/ height
;
449 if (!PUSH_SPACE(push
, 40))
452 PUSH_REFN (push
, buf
->bo
, buf
->domain
| NOUVEAU_BO_WR
);
454 BEGIN_NVC0(push
, NVC0_3D(CLEAR_COLOR(0)), 4);
455 PUSH_DATAf(push
, color
.f
[0]);
456 PUSH_DATAf(push
, color
.f
[1]);
457 PUSH_DATAf(push
, color
.f
[2]);
458 PUSH_DATAf(push
, color
.f
[3]);
459 BEGIN_NVC0(push
, NVC0_3D(SCREEN_SCISSOR_HORIZ
), 2);
460 PUSH_DATA (push
, width
<< 16);
461 PUSH_DATA (push
, height
<< 16);
463 IMMED_NVC0(push
, NVC0_3D(RT_CONTROL
), 1);
465 BEGIN_NVC0(push
, NVC0_3D(RT_ADDRESS_HIGH(0)), 9);
466 PUSH_DATAh(push
, buf
->address
+ offset
);
467 PUSH_DATA (push
, buf
->address
+ offset
);
468 PUSH_DATA (push
, width
* data_size
);
469 PUSH_DATA (push
, height
);
470 PUSH_DATA (push
, nvc0_format_table
[dst_fmt
].rt
);
471 PUSH_DATA (push
, NVC0_3D_RT_TILE_MODE_LINEAR
);
476 IMMED_NVC0(push
, NVC0_3D(ZETA_ENABLE
), 0);
477 IMMED_NVC0(push
, NVC0_3D(MULTISAMPLE_MODE
), 0);
479 IMMED_NVC0(push
, NVC0_3D(COND_MODE
), NVC0_3D_COND_MODE_ALWAYS
);
481 IMMED_NVC0(push
, NVC0_3D(CLEAR_BUFFERS
), 0x3c);
483 if (width
* height
!= elements
) {
484 offset
+= width
* height
* data_size
;
485 width
= elements
- width
* height
;
488 BEGIN_NVC0(push
, NVC0_3D(RT_ADDRESS_HIGH(0)), 4);
489 PUSH_DATAh(push
, buf
->address
+ offset
);
490 PUSH_DATA (push
, buf
->address
+ offset
);
491 PUSH_DATA (push
, width
* data_size
);
492 PUSH_DATA (push
, height
);
494 IMMED_NVC0(push
, NVC0_3D(CLEAR_BUFFERS
), 0x3c);
497 IMMED_NVC0(push
, NVC0_3D(COND_MODE
), nvc0
->cond_condmode
);
499 nouveau_fence_ref(nvc0
->screen
->base
.fence
.current
, &buf
->fence
);
500 nouveau_fence_ref(nvc0
->screen
->base
.fence
.current
, &buf
->fence_wr
);
501 nvc0
->dirty
|= NVC0_NEW_FRAMEBUFFER
;
505 nvc0_clear_depth_stencil(struct pipe_context
*pipe
,
506 struct pipe_surface
*dst
,
507 unsigned clear_flags
,
510 unsigned dstx
, unsigned dsty
,
511 unsigned width
, unsigned height
)
513 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
514 struct nouveau_pushbuf
*push
= nvc0
->base
.pushbuf
;
515 struct nv50_miptree
*mt
= nv50_miptree(dst
->texture
);
516 struct nv50_surface
*sf
= nv50_surface(dst
);
518 int unk
= mt
->base
.base
.target
== PIPE_TEXTURE_2D
;
521 assert(dst
->texture
->target
!= PIPE_BUFFER
);
523 if (!PUSH_SPACE(push
, 32 + sf
->depth
))
526 PUSH_REFN (push
, mt
->base
.bo
, mt
->base
.domain
| NOUVEAU_BO_WR
);
528 if (clear_flags
& PIPE_CLEAR_DEPTH
) {
529 BEGIN_NVC0(push
, NVC0_3D(CLEAR_DEPTH
), 1);
530 PUSH_DATAf(push
, depth
);
531 mode
|= NVC0_3D_CLEAR_BUFFERS_Z
;
534 if (clear_flags
& PIPE_CLEAR_STENCIL
) {
535 BEGIN_NVC0(push
, NVC0_3D(CLEAR_STENCIL
), 1);
536 PUSH_DATA (push
, stencil
& 0xff);
537 mode
|= NVC0_3D_CLEAR_BUFFERS_S
;
540 BEGIN_NVC0(push
, NVC0_3D(SCREEN_SCISSOR_HORIZ
), 2);
541 PUSH_DATA (push
, ( width
<< 16) | dstx
);
542 PUSH_DATA (push
, (height
<< 16) | dsty
);
544 BEGIN_NVC0(push
, NVC0_3D(ZETA_ADDRESS_HIGH
), 5);
545 PUSH_DATAh(push
, mt
->base
.address
+ sf
->offset
);
546 PUSH_DATA (push
, mt
->base
.address
+ sf
->offset
);
547 PUSH_DATA (push
, nvc0_format_table
[dst
->format
].rt
);
548 PUSH_DATA (push
, mt
->level
[sf
->base
.u
.tex
.level
].tile_mode
);
549 PUSH_DATA (push
, mt
->layer_stride
>> 2);
550 BEGIN_NVC0(push
, NVC0_3D(ZETA_ENABLE
), 1);
552 BEGIN_NVC0(push
, NVC0_3D(ZETA_HORIZ
), 3);
553 PUSH_DATA (push
, sf
->width
);
554 PUSH_DATA (push
, sf
->height
);
555 PUSH_DATA (push
, (unk
<< 16) | (dst
->u
.tex
.first_layer
+ sf
->depth
));
556 BEGIN_NVC0(push
, NVC0_3D(ZETA_BASE_LAYER
), 1);
557 PUSH_DATA (push
, dst
->u
.tex
.first_layer
);
558 IMMED_NVC0(push
, NVC0_3D(MULTISAMPLE_MODE
), mt
->ms_mode
);
560 IMMED_NVC0(push
, NVC0_3D(COND_MODE
), NVC0_3D_COND_MODE_ALWAYS
);
562 BEGIN_NIC0(push
, NVC0_3D(CLEAR_BUFFERS
), sf
->depth
);
563 for (z
= 0; z
< sf
->depth
; ++z
) {
564 PUSH_DATA (push
, mode
|
565 (z
<< NVC0_3D_CLEAR_BUFFERS_LAYER__SHIFT
));
568 IMMED_NVC0(push
, NVC0_3D(COND_MODE
), nvc0
->cond_condmode
);
570 nvc0
->dirty
|= NVC0_NEW_FRAMEBUFFER
;
574 nvc0_clear(struct pipe_context
*pipe
, unsigned buffers
,
575 const union pipe_color_union
*color
,
576 double depth
, unsigned stencil
)
578 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
579 struct nouveau_pushbuf
*push
= nvc0
->base
.pushbuf
;
580 struct pipe_framebuffer_state
*fb
= &nvc0
->framebuffer
;
584 /* don't need NEW_BLEND, COLOR_MASK doesn't affect CLEAR_BUFFERS */
585 if (!nvc0_state_validate(nvc0
, NVC0_NEW_FRAMEBUFFER
, 9 + (fb
->nr_cbufs
* 2)))
588 if (buffers
& PIPE_CLEAR_COLOR
&& fb
->nr_cbufs
) {
589 BEGIN_NVC0(push
, NVC0_3D(CLEAR_COLOR(0)), 4);
590 PUSH_DATAf(push
, color
->f
[0]);
591 PUSH_DATAf(push
, color
->f
[1]);
592 PUSH_DATAf(push
, color
->f
[2]);
593 PUSH_DATAf(push
, color
->f
[3]);
594 if (buffers
& PIPE_CLEAR_COLOR0
)
596 NVC0_3D_CLEAR_BUFFERS_R
| NVC0_3D_CLEAR_BUFFERS_G
|
597 NVC0_3D_CLEAR_BUFFERS_B
| NVC0_3D_CLEAR_BUFFERS_A
;
600 if (buffers
& PIPE_CLEAR_DEPTH
) {
601 BEGIN_NVC0(push
, NVC0_3D(CLEAR_DEPTH
), 1);
602 PUSH_DATA (push
, fui(depth
));
603 mode
|= NVC0_3D_CLEAR_BUFFERS_Z
;
606 if (buffers
& PIPE_CLEAR_STENCIL
) {
607 BEGIN_NVC0(push
, NVC0_3D(CLEAR_STENCIL
), 1);
608 PUSH_DATA (push
, stencil
& 0xff);
609 mode
|= NVC0_3D_CLEAR_BUFFERS_S
;
613 int zs_layers
= 0, color0_layers
= 0;
614 if (fb
->cbufs
[0] && (mode
& 0x3c))
615 color0_layers
= fb
->cbufs
[0]->u
.tex
.last_layer
-
616 fb
->cbufs
[0]->u
.tex
.first_layer
+ 1;
617 if (fb
->zsbuf
&& (mode
& ~0x3c))
618 zs_layers
= fb
->zsbuf
->u
.tex
.last_layer
-
619 fb
->zsbuf
->u
.tex
.first_layer
+ 1;
621 for (j
= 0; j
< MIN2(zs_layers
, color0_layers
); j
++) {
622 BEGIN_NVC0(push
, NVC0_3D(CLEAR_BUFFERS
), 1);
623 PUSH_DATA(push
, mode
| (j
<< NVC0_3D_CLEAR_BUFFERS_LAYER__SHIFT
));
625 for (k
= j
; k
< zs_layers
; k
++) {
626 BEGIN_NVC0(push
, NVC0_3D(CLEAR_BUFFERS
), 1);
627 PUSH_DATA(push
, (mode
& ~0x3c) | (k
<< NVC0_3D_CLEAR_BUFFERS_LAYER__SHIFT
));
629 for (k
= j
; k
< color0_layers
; k
++) {
630 BEGIN_NVC0(push
, NVC0_3D(CLEAR_BUFFERS
), 1);
631 PUSH_DATA(push
, (mode
& 0x3c) | (k
<< NVC0_3D_CLEAR_BUFFERS_LAYER__SHIFT
));
635 for (i
= 1; i
< fb
->nr_cbufs
; i
++) {
636 struct pipe_surface
*sf
= fb
->cbufs
[i
];
637 if (!sf
|| !(buffers
& (PIPE_CLEAR_COLOR0
<< i
)))
639 for (j
= 0; j
<= sf
->u
.tex
.last_layer
- sf
->u
.tex
.first_layer
; j
++) {
640 BEGIN_NVC0(push
, NVC0_3D(CLEAR_BUFFERS
), 1);
641 PUSH_DATA (push
, (i
<< 6) | 0x3c |
642 (j
<< NVC0_3D_CLEAR_BUFFERS_LAYER__SHIFT
));
648 /* =============================== BLIT CODE ===================================
653 struct nvc0_program
*fp
[NV50_BLIT_MAX_TEXTURE_TYPES
][NV50_BLIT_MODES
];
654 struct nvc0_program vp
;
656 struct nv50_tsc_entry sampler
[2]; /* nearest, bilinear */
660 struct nvc0_screen
*screen
;
665 struct nvc0_context
*nvc0
;
666 struct nvc0_program
*fp
;
670 uint8_t render_condition_enable
;
671 enum pipe_texture_target target
;
673 struct pipe_framebuffer_state fb
;
674 struct nvc0_rasterizer_stateobj
*rast
;
675 struct nvc0_program
*vp
;
676 struct nvc0_program
*tcp
;
677 struct nvc0_program
*tep
;
678 struct nvc0_program
*gp
;
679 struct nvc0_program
*fp
;
680 unsigned num_textures
[5];
681 unsigned num_samplers
[5];
682 struct pipe_sampler_view
*texture
[2];
683 struct nv50_tsc_entry
*sampler
[2];
684 unsigned min_samples
;
687 struct nvc0_rasterizer_stateobj rast
;
691 nvc0_blitter_make_vp(struct nvc0_blitter
*blit
)
693 static const uint32_t code_nvc0
[] =
695 0xfff11c26, 0x06000080, /* vfetch b64 $r4:$r5 a[0x80] */
696 0xfff01c46, 0x06000090, /* vfetch b96 $r0:$r1:$r2 a[0x90] */
697 0x13f01c26, 0x0a7e0070, /* export b64 o[0x70] $r4:$r5 */
698 0x03f01c46, 0x0a7e0080, /* export b96 o[0x80] $r0:$r1:$r2 */
699 0x00001de7, 0x80000000, /* exit */
701 static const uint32_t code_nve4
[] =
703 0x00000007, 0x20000000, /* sched */
704 0xfff11c26, 0x06000080, /* vfetch b64 $r4:$r5 a[0x80] */
705 0xfff01c46, 0x06000090, /* vfetch b96 $r0:$r1:$r2 a[0x90] */
706 0x13f01c26, 0x0a7e0070, /* export b64 o[0x70] $r4:$r5 */
707 0x03f01c46, 0x0a7e0080, /* export b96 o[0x80] $r0:$r1:$r2 */
708 0x00001de7, 0x80000000, /* exit */
710 static const uint32_t code_gk110
[] =
712 0x00000000, 0x08000000, /* sched */
713 0x401ffc12, 0x7ec7fc00, /* ld b64 $r4d a[0x80] 0x0 0x0 */
714 0x481ffc02, 0x7ecbfc00, /* ld b96 $r0t a[0x90] 0x0 0x0 */
715 0x381ffc12, 0x7f07fc00, /* st b64 a[0x70] $r4d 0x0 0x0 */
716 0x401ffc02, 0x7f0bfc00, /* st b96 a[0x80] $r0t 0x0 0x0 */
717 0x001c003c, 0x18000000, /* exit */
719 static const uint32_t code_gm107
[] =
721 0xfc0007e0, 0x001f8000, /* sched 0x7e0 0x7e0 0x7e0 */
722 0x0807ff04, 0xefd8ff80, /* ld b64 $r4 a[0x80] 0x0 */
723 0x0907ff00, 0xefd97f80, /* ld b96 $r0 a[0x90] 0x0 */
724 0x0707ff04, 0xeff0ff80, /* st b64 a[0x70] $r4 0x0 */
725 0xfc0007e0, 0x00000000, /* sched 0x7e0 0x7e0 0x0 */
726 0x0807ff00, 0xeff17f80, /* st b96 a[0x80] $r0 0x0 */
727 0x0007000f, 0xe3000000, /* exit */
730 blit
->vp
.type
= PIPE_SHADER_VERTEX
;
731 blit
->vp
.translated
= true;
732 if (blit
->screen
->base
.class_3d
>= GM107_3D_CLASS
) {
733 blit
->vp
.code
= (uint32_t *)code_gm107
; /* const_cast */
734 blit
->vp
.code_size
= sizeof(code_gm107
);
736 if (blit
->screen
->base
.class_3d
>= NVF0_3D_CLASS
) {
737 blit
->vp
.code
= (uint32_t *)code_gk110
; /* const_cast */
738 blit
->vp
.code_size
= sizeof(code_gk110
);
740 if (blit
->screen
->base
.class_3d
>= NVE4_3D_CLASS
) {
741 blit
->vp
.code
= (uint32_t *)code_nve4
; /* const_cast */
742 blit
->vp
.code_size
= sizeof(code_nve4
);
744 blit
->vp
.code
= (uint32_t *)code_nvc0
; /* const_cast */
745 blit
->vp
.code_size
= sizeof(code_nvc0
);
747 blit
->vp
.num_gprs
= 6;
748 blit
->vp
.vp
.edgeflag
= PIPE_MAX_ATTRIBS
;
750 blit
->vp
.hdr
[0] = 0x00020461; /* vertprog magic */
751 blit
->vp
.hdr
[4] = 0x000ff000; /* no outputs read */
752 blit
->vp
.hdr
[6] = 0x00000073; /* a[0x80].xy, a[0x90].xyz */
753 blit
->vp
.hdr
[13] = 0x00073000; /* o[0x70].xy, o[0x80].xyz */
757 nvc0_blitter_make_sampler(struct nvc0_blitter
*blit
)
759 /* clamp to edge, min/max lod = 0, nearest filtering */
761 blit
->sampler
[0].id
= -1;
763 blit
->sampler
[0].tsc
[0] = NV50_TSC_0_SRGB_CONVERSION_ALLOWED
|
764 (NV50_TSC_WRAP_CLAMP_TO_EDGE
<< NV50_TSC_0_WRAPS__SHIFT
) |
765 (NV50_TSC_WRAP_CLAMP_TO_EDGE
<< NV50_TSC_0_WRAPT__SHIFT
) |
766 (NV50_TSC_WRAP_CLAMP_TO_EDGE
<< NV50_TSC_0_WRAPR__SHIFT
);
767 blit
->sampler
[0].tsc
[1] =
768 NV50_TSC_1_MAGF_NEAREST
| NV50_TSC_1_MINF_NEAREST
| NV50_TSC_1_MIPF_NONE
;
770 /* clamp to edge, min/max lod = 0, bilinear filtering */
772 blit
->sampler
[1].id
= -1;
774 blit
->sampler
[1].tsc
[0] = blit
->sampler
[0].tsc
[0];
775 blit
->sampler
[1].tsc
[1] =
776 NV50_TSC_1_MAGF_LINEAR
| NV50_TSC_1_MINF_LINEAR
| NV50_TSC_1_MIPF_NONE
;
780 nvc0_blit_select_fp(struct nvc0_blitctx
*ctx
, const struct pipe_blit_info
*info
)
782 struct nvc0_blitter
*blitter
= ctx
->nvc0
->screen
->blitter
;
784 const enum pipe_texture_target ptarg
=
785 nv50_blit_reinterpret_pipe_texture_target(info
->src
.resource
->target
);
787 const unsigned targ
= nv50_blit_texture_type(ptarg
);
788 const unsigned mode
= ctx
->mode
;
790 if (!blitter
->fp
[targ
][mode
]) {
791 pipe_mutex_lock(blitter
->mutex
);
792 if (!blitter
->fp
[targ
][mode
])
793 blitter
->fp
[targ
][mode
] =
794 nv50_blitter_make_fp(&ctx
->nvc0
->base
.pipe
, mode
, ptarg
);
795 pipe_mutex_unlock(blitter
->mutex
);
797 ctx
->fp
= blitter
->fp
[targ
][mode
];
801 nvc0_blit_set_dst(struct nvc0_blitctx
*ctx
,
802 struct pipe_resource
*res
, unsigned level
, unsigned layer
,
803 enum pipe_format format
)
805 struct nvc0_context
*nvc0
= ctx
->nvc0
;
806 struct pipe_context
*pipe
= &nvc0
->base
.pipe
;
807 struct pipe_surface templ
;
809 if (util_format_is_depth_or_stencil(format
))
810 templ
.format
= nv50_blit_zeta_to_colour_format(format
);
812 templ
.format
= format
;
814 templ
.u
.tex
.level
= level
;
815 templ
.u
.tex
.first_layer
= templ
.u
.tex
.last_layer
= layer
;
818 templ
.u
.tex
.first_layer
= 0;
819 templ
.u
.tex
.last_layer
=
820 (res
->target
== PIPE_TEXTURE_3D
? res
->depth0
: res
->array_size
) - 1;
823 nvc0
->framebuffer
.cbufs
[0] = nvc0_miptree_surface_new(pipe
, res
, &templ
);
824 nvc0
->framebuffer
.nr_cbufs
= 1;
825 nvc0
->framebuffer
.zsbuf
= NULL
;
826 nvc0
->framebuffer
.width
= nvc0
->framebuffer
.cbufs
[0]->width
;
827 nvc0
->framebuffer
.height
= nvc0
->framebuffer
.cbufs
[0]->height
;
831 nvc0_blit_set_src(struct nvc0_blitctx
*ctx
,
832 struct pipe_resource
*res
, unsigned level
, unsigned layer
,
833 enum pipe_format format
, const uint8_t filter
)
835 struct nvc0_context
*nvc0
= ctx
->nvc0
;
836 struct pipe_context
*pipe
= &nvc0
->base
.pipe
;
837 struct pipe_sampler_view templ
;
840 enum pipe_texture_target target
;
842 target
= nv50_blit_reinterpret_pipe_texture_target(res
->target
);
844 templ
.format
= format
;
845 templ
.u
.tex
.first_layer
= templ
.u
.tex
.last_layer
= layer
;
846 templ
.u
.tex
.first_level
= templ
.u
.tex
.last_level
= level
;
847 templ
.swizzle_r
= PIPE_SWIZZLE_RED
;
848 templ
.swizzle_g
= PIPE_SWIZZLE_GREEN
;
849 templ
.swizzle_b
= PIPE_SWIZZLE_BLUE
;
850 templ
.swizzle_a
= PIPE_SWIZZLE_ALPHA
;
853 templ
.u
.tex
.first_layer
= 0;
854 templ
.u
.tex
.last_layer
=
855 (res
->target
== PIPE_TEXTURE_3D
? res
->depth0
: res
->array_size
) - 1;
858 flags
= res
->last_level
? 0 : NV50_TEXVIEW_SCALED_COORDS
;
859 flags
|= NV50_TEXVIEW_ACCESS_RESOLVE
;
860 if (filter
&& res
->nr_samples
== 8)
861 flags
|= NV50_TEXVIEW_FILTER_MSAA8
;
863 nvc0
->textures
[4][0] = nvc0_create_texture_view(
864 pipe
, res
, &templ
, flags
, target
);
865 nvc0
->textures
[4][1] = NULL
;
867 for (s
= 0; s
<= 3; ++s
)
868 nvc0
->num_textures
[s
] = 0;
869 nvc0
->num_textures
[4] = 1;
871 templ
.format
= nv50_zs_to_s_format(format
);
872 if (templ
.format
!= format
) {
873 nvc0
->textures
[4][1] = nvc0_create_texture_view(
874 pipe
, res
, &templ
, flags
, target
);
875 nvc0
->num_textures
[4] = 2;
880 nvc0_blitctx_prepare_state(struct nvc0_blitctx
*blit
)
882 struct nouveau_pushbuf
*push
= blit
->nvc0
->base
.pushbuf
;
884 /* TODO: maybe make this a MACRO (if we need more logic) ? */
886 if (blit
->nvc0
->cond_query
&& !blit
->render_condition_enable
)
887 IMMED_NVC0(push
, NVC0_3D(COND_MODE
), NVC0_3D_COND_MODE_ALWAYS
);
890 BEGIN_NVC0(push
, NVC0_3D(COLOR_MASK(0)), 1);
891 PUSH_DATA (push
, blit
->color_mask
);
892 IMMED_NVC0(push
, NVC0_3D(BLEND_ENABLE(0)), 0);
893 IMMED_NVC0(push
, NVC0_3D(LOGIC_OP_ENABLE
), 0);
895 /* rasterizer state */
896 IMMED_NVC0(push
, NVC0_3D(FRAG_COLOR_CLAMP_EN
), 0);
897 IMMED_NVC0(push
, NVC0_3D(MULTISAMPLE_ENABLE
), 0);
898 BEGIN_NVC0(push
, NVC0_3D(MSAA_MASK(0)), 4);
899 PUSH_DATA (push
, 0xffff);
900 PUSH_DATA (push
, 0xffff);
901 PUSH_DATA (push
, 0xffff);
902 PUSH_DATA (push
, 0xffff);
903 BEGIN_NVC0(push
, NVC0_3D(MACRO_POLYGON_MODE_FRONT
), 1);
904 PUSH_DATA (push
, NVC0_3D_MACRO_POLYGON_MODE_FRONT_FILL
);
905 BEGIN_NVC0(push
, NVC0_3D(MACRO_POLYGON_MODE_BACK
), 1);
906 PUSH_DATA (push
, NVC0_3D_MACRO_POLYGON_MODE_BACK_FILL
);
907 IMMED_NVC0(push
, NVC0_3D(POLYGON_SMOOTH_ENABLE
), 0);
908 IMMED_NVC0(push
, NVC0_3D(POLYGON_OFFSET_FILL_ENABLE
), 0);
909 IMMED_NVC0(push
, NVC0_3D(POLYGON_STIPPLE_ENABLE
), 0);
910 IMMED_NVC0(push
, NVC0_3D(CULL_FACE_ENABLE
), 0);
913 IMMED_NVC0(push
, NVC0_3D(DEPTH_TEST_ENABLE
), 0);
914 IMMED_NVC0(push
, NVC0_3D(DEPTH_BOUNDS_EN
), 0);
915 IMMED_NVC0(push
, NVC0_3D(STENCIL_ENABLE
), 0);
916 IMMED_NVC0(push
, NVC0_3D(ALPHA_TEST_ENABLE
), 0);
918 /* disable transform feedback */
919 IMMED_NVC0(push
, NVC0_3D(TFB_ENABLE
), 0);
923 nvc0_blitctx_pre_blit(struct nvc0_blitctx
*ctx
)
925 struct nvc0_context
*nvc0
= ctx
->nvc0
;
926 struct nvc0_blitter
*blitter
= nvc0
->screen
->blitter
;
929 ctx
->saved
.fb
.width
= nvc0
->framebuffer
.width
;
930 ctx
->saved
.fb
.height
= nvc0
->framebuffer
.height
;
931 ctx
->saved
.fb
.nr_cbufs
= nvc0
->framebuffer
.nr_cbufs
;
932 ctx
->saved
.fb
.cbufs
[0] = nvc0
->framebuffer
.cbufs
[0];
933 ctx
->saved
.fb
.zsbuf
= nvc0
->framebuffer
.zsbuf
;
935 ctx
->saved
.rast
= nvc0
->rast
;
937 ctx
->saved
.vp
= nvc0
->vertprog
;
938 ctx
->saved
.tcp
= nvc0
->tctlprog
;
939 ctx
->saved
.tep
= nvc0
->tevlprog
;
940 ctx
->saved
.gp
= nvc0
->gmtyprog
;
941 ctx
->saved
.fp
= nvc0
->fragprog
;
943 ctx
->saved
.min_samples
= nvc0
->min_samples
;
945 nvc0
->rast
= &ctx
->rast
;
947 nvc0
->vertprog
= &blitter
->vp
;
948 nvc0
->tctlprog
= NULL
;
949 nvc0
->tevlprog
= NULL
;
950 nvc0
->gmtyprog
= NULL
;
951 nvc0
->fragprog
= ctx
->fp
;
953 for (s
= 0; s
<= 4; ++s
) {
954 ctx
->saved
.num_textures
[s
] = nvc0
->num_textures
[s
];
955 ctx
->saved
.num_samplers
[s
] = nvc0
->num_samplers
[s
];
956 nvc0
->textures_dirty
[s
] = (1 << nvc0
->num_textures
[s
]) - 1;
957 nvc0
->samplers_dirty
[s
] = (1 << nvc0
->num_samplers
[s
]) - 1;
959 ctx
->saved
.texture
[0] = nvc0
->textures
[4][0];
960 ctx
->saved
.texture
[1] = nvc0
->textures
[4][1];
961 ctx
->saved
.sampler
[0] = nvc0
->samplers
[4][0];
962 ctx
->saved
.sampler
[1] = nvc0
->samplers
[4][1];
964 nvc0
->samplers
[4][0] = &blitter
->sampler
[ctx
->filter
];
965 nvc0
->samplers
[4][1] = &blitter
->sampler
[ctx
->filter
];
967 for (s
= 0; s
<= 3; ++s
)
968 nvc0
->num_samplers
[s
] = 0;
969 nvc0
->num_samplers
[4] = 2;
971 nvc0
->min_samples
= 1;
973 ctx
->saved
.dirty
= nvc0
->dirty
;
975 nvc0
->textures_dirty
[4] |= 3;
976 nvc0
->samplers_dirty
[4] |= 3;
978 nouveau_bufctx_reset(nvc0
->bufctx_3d
, NVC0_BIND_FB
);
979 nouveau_bufctx_reset(nvc0
->bufctx_3d
, NVC0_BIND_TEX(4, 0));
980 nouveau_bufctx_reset(nvc0
->bufctx_3d
, NVC0_BIND_TEX(4, 1));
982 nvc0
->dirty
= NVC0_NEW_FRAMEBUFFER
| NVC0_NEW_MIN_SAMPLES
|
983 NVC0_NEW_VERTPROG
| NVC0_NEW_FRAGPROG
|
984 NVC0_NEW_TCTLPROG
| NVC0_NEW_TEVLPROG
| NVC0_NEW_GMTYPROG
|
985 NVC0_NEW_TEXTURES
| NVC0_NEW_SAMPLERS
;
989 nvc0_blitctx_post_blit(struct nvc0_blitctx
*blit
)
991 struct nvc0_context
*nvc0
= blit
->nvc0
;
994 pipe_surface_reference(&nvc0
->framebuffer
.cbufs
[0], NULL
);
996 nvc0
->framebuffer
.width
= blit
->saved
.fb
.width
;
997 nvc0
->framebuffer
.height
= blit
->saved
.fb
.height
;
998 nvc0
->framebuffer
.nr_cbufs
= blit
->saved
.fb
.nr_cbufs
;
999 nvc0
->framebuffer
.cbufs
[0] = blit
->saved
.fb
.cbufs
[0];
1000 nvc0
->framebuffer
.zsbuf
= blit
->saved
.fb
.zsbuf
;
1002 nvc0
->rast
= blit
->saved
.rast
;
1004 nvc0
->vertprog
= blit
->saved
.vp
;
1005 nvc0
->tctlprog
= blit
->saved
.tcp
;
1006 nvc0
->tevlprog
= blit
->saved
.tep
;
1007 nvc0
->gmtyprog
= blit
->saved
.gp
;
1008 nvc0
->fragprog
= blit
->saved
.fp
;
1010 nvc0
->min_samples
= blit
->saved
.min_samples
;
1012 pipe_sampler_view_reference(&nvc0
->textures
[4][0], NULL
);
1013 pipe_sampler_view_reference(&nvc0
->textures
[4][1], NULL
);
1015 for (s
= 0; s
<= 4; ++s
) {
1016 nvc0
->num_textures
[s
] = blit
->saved
.num_textures
[s
];
1017 nvc0
->num_samplers
[s
] = blit
->saved
.num_samplers
[s
];
1018 nvc0
->textures_dirty
[s
] = (1 << nvc0
->num_textures
[s
]) - 1;
1019 nvc0
->samplers_dirty
[s
] = (1 << nvc0
->num_samplers
[s
]) - 1;
1021 nvc0
->textures
[4][0] = blit
->saved
.texture
[0];
1022 nvc0
->textures
[4][1] = blit
->saved
.texture
[1];
1023 nvc0
->samplers
[4][0] = blit
->saved
.sampler
[0];
1024 nvc0
->samplers
[4][1] = blit
->saved
.sampler
[1];
1026 nvc0
->textures_dirty
[4] |= 3;
1027 nvc0
->samplers_dirty
[4] |= 3;
1029 if (nvc0
->cond_query
&& !blit
->render_condition_enable
)
1030 nvc0
->base
.pipe
.render_condition(&nvc0
->base
.pipe
, nvc0
->cond_query
,
1031 nvc0
->cond_cond
, nvc0
->cond_mode
);
1033 nouveau_bufctx_reset(nvc0
->bufctx_3d
, NVC0_BIND_FB
);
1034 nouveau_bufctx_reset(nvc0
->bufctx_3d
, NVC0_BIND_TEX(4, 0));
1035 nouveau_bufctx_reset(nvc0
->bufctx_3d
, NVC0_BIND_TEX(4, 1));
1037 nvc0
->dirty
= blit
->saved
.dirty
|
1038 (NVC0_NEW_FRAMEBUFFER
| NVC0_NEW_SCISSOR
| NVC0_NEW_SAMPLE_MASK
|
1039 NVC0_NEW_RASTERIZER
| NVC0_NEW_ZSA
| NVC0_NEW_BLEND
|
1041 NVC0_NEW_TEXTURES
| NVC0_NEW_SAMPLERS
|
1042 NVC0_NEW_VERTPROG
| NVC0_NEW_FRAGPROG
|
1043 NVC0_NEW_TCTLPROG
| NVC0_NEW_TEVLPROG
| NVC0_NEW_GMTYPROG
|
1044 NVC0_NEW_TFB_TARGETS
| NVC0_NEW_VERTEX
| NVC0_NEW_ARRAYS
);
1045 nvc0
->scissors_dirty
|= 1;
1046 nvc0
->viewports_dirty
|= 1;
1048 nvc0
->base
.pipe
.set_min_samples(&nvc0
->base
.pipe
, blit
->saved
.min_samples
);
1052 nvc0_blit_3d(struct nvc0_context
*nvc0
, const struct pipe_blit_info
*info
)
1054 struct nvc0_blitctx
*blit
= nvc0
->blit
;
1055 struct nouveau_pushbuf
*push
= nvc0
->base
.pushbuf
;
1056 struct pipe_resource
*src
= info
->src
.resource
;
1057 struct pipe_resource
*dst
= info
->dst
.resource
;
1058 struct nouveau_bo
*vtxbuf_bo
;
1059 uint32_t stride
, length
, *vbuf
;
1061 int32_t minx
, maxx
, miny
, maxy
;
1063 float x0
, x1
, y0
, y1
, z
;
1065 float x_range
, y_range
;
1067 blit
->mode
= nv50_blit_select_mode(info
);
1068 blit
->color_mask
= nv50_blit_derive_color_mask(info
);
1069 blit
->filter
= nv50_blit_get_filter(info
);
1070 blit
->render_condition_enable
= info
->render_condition_enable
;
1072 nvc0_blit_select_fp(blit
, info
);
1073 nvc0_blitctx_pre_blit(blit
);
1075 nvc0_blit_set_dst(blit
, dst
, info
->dst
.level
, -1, info
->dst
.format
);
1076 nvc0_blit_set_src(blit
, src
, info
->src
.level
, -1, info
->src
.format
,
1079 nvc0_blitctx_prepare_state(blit
);
1081 nvc0_state_validate(nvc0
, ~0, 48);
1083 x_range
= (float)info
->src
.box
.width
/ (float)info
->dst
.box
.width
;
1084 y_range
= (float)info
->src
.box
.height
/ (float)info
->dst
.box
.height
;
1086 x0
= (float)info
->src
.box
.x
- x_range
* (float)info
->dst
.box
.x
;
1087 y0
= (float)info
->src
.box
.y
- y_range
* (float)info
->dst
.box
.y
;
1089 x1
= x0
+ 16384.0f
* x_range
;
1090 y1
= y0
+ 16384.0f
* y_range
;
1092 x0
*= (float)(1 << nv50_miptree(src
)->ms_x
);
1093 x1
*= (float)(1 << nv50_miptree(src
)->ms_x
);
1094 y0
*= (float)(1 << nv50_miptree(src
)->ms_y
);
1095 y1
*= (float)(1 << nv50_miptree(src
)->ms_y
);
1097 dz
= (float)info
->src
.box
.depth
/ (float)info
->dst
.box
.depth
;
1098 z
= (float)info
->src
.box
.z
;
1099 if (nv50_miptree(src
)->layout_3d
)
1102 if (src
->last_level
> 0) {
1103 /* If there are mip maps, GPU always assumes normalized coordinates. */
1104 const unsigned l
= info
->src
.level
;
1105 const float fh
= u_minify(src
->width0
<< nv50_miptree(src
)->ms_x
, l
);
1106 const float fv
= u_minify(src
->height0
<< nv50_miptree(src
)->ms_y
, l
);
1111 if (nv50_miptree(src
)->layout_3d
) {
1112 z
/= u_minify(src
->depth0
, l
);
1113 dz
/= u_minify(src
->depth0
, l
);
1117 IMMED_NVC0(push
, NVC0_3D(VIEWPORT_TRANSFORM_EN
), 0);
1118 IMMED_NVC0(push
, NVC0_3D(VIEW_VOLUME_CLIP_CTRL
), 0x2 |
1119 NVC0_3D_VIEW_VOLUME_CLIP_CTRL_DEPTH_RANGE_0_1
);
1120 BEGIN_NVC0(push
, NVC0_3D(VIEWPORT_HORIZ(0)), 2);
1121 PUSH_DATA (push
, nvc0
->framebuffer
.width
<< 16);
1122 PUSH_DATA (push
, nvc0
->framebuffer
.height
<< 16);
1124 /* Draw a large triangle in screen coordinates covering the whole
1125 * render target, with scissors defining the destination region.
1126 * The vertex is supplied with non-normalized texture coordinates
1127 * arranged in a way to yield the desired offset and scale.
1130 minx
= info
->dst
.box
.x
;
1131 maxx
= info
->dst
.box
.x
+ info
->dst
.box
.width
;
1132 miny
= info
->dst
.box
.y
;
1133 maxy
= info
->dst
.box
.y
+ info
->dst
.box
.height
;
1134 if (info
->scissor_enable
) {
1135 minx
= MAX2(minx
, info
->scissor
.minx
);
1136 maxx
= MIN2(maxx
, info
->scissor
.maxx
);
1137 miny
= MAX2(miny
, info
->scissor
.miny
);
1138 maxy
= MIN2(maxy
, info
->scissor
.maxy
);
1140 BEGIN_NVC0(push
, NVC0_3D(SCISSOR_HORIZ(0)), 2);
1141 PUSH_DATA (push
, (maxx
<< 16) | minx
);
1142 PUSH_DATA (push
, (maxy
<< 16) | miny
);
1144 stride
= (3 + 2) * 4;
1145 length
= stride
* 3 * info
->dst
.box
.depth
;
1147 vbuf
= nouveau_scratch_get(&nvc0
->base
, length
, &vtxbuf
, &vtxbuf_bo
);
1153 BCTX_REFN_bo(nvc0
->bufctx_3d
, VTX_TMP
, NOUVEAU_BO_GART
| NOUVEAU_BO_RD
, vtxbuf_bo
);
1154 nouveau_pushbuf_validate(push
);
1156 BEGIN_NVC0(push
, NVC0_3D(VERTEX_ARRAY_FETCH(0)), 4);
1157 PUSH_DATA (push
, NVC0_3D_VERTEX_ARRAY_FETCH_ENABLE
| stride
<<
1158 NVC0_3D_VERTEX_ARRAY_FETCH_STRIDE__SHIFT
);
1159 PUSH_DATAh(push
, vtxbuf
);
1160 PUSH_DATA (push
, vtxbuf
);
1161 PUSH_DATA (push
, 0);
1162 BEGIN_NVC0(push
, NVC0_3D(VERTEX_ARRAY_LIMIT_HIGH(0)), 2);
1163 PUSH_DATAh(push
, vtxbuf
+ length
- 1);
1164 PUSH_DATA (push
, vtxbuf
+ length
- 1);
1166 n
= MAX2(2, nvc0
->state
.num_vtxelts
);
1168 BEGIN_NVC0(push
, NVC0_3D(VERTEX_ATTRIB_FORMAT(0)), n
);
1169 PUSH_DATA (push
, NVC0_3D_VERTEX_ATTRIB_FORMAT_TYPE_FLOAT
|
1170 NVC0_3D_VERTEX_ATTRIB_FORMAT_SIZE_32_32
| 0x00 <<
1171 NVC0_3D_VERTEX_ATTRIB_FORMAT_OFFSET__SHIFT
);
1172 PUSH_DATA (push
, NVC0_3D_VERTEX_ATTRIB_FORMAT_TYPE_FLOAT
|
1173 NVC0_3D_VERTEX_ATTRIB_FORMAT_SIZE_32_32_32
| 0x08 <<
1174 NVC0_3D_VERTEX_ATTRIB_FORMAT_OFFSET__SHIFT
);
1175 for (i
= 2; i
< n
; i
++) {
1176 PUSH_DATA(push
, NVC0_3D_VERTEX_ATTRIB_FORMAT_TYPE_FLOAT
|
1177 NVC0_3D_VERTEX_ATTRIB_FORMAT_SIZE_32
|
1178 NVC0_3D_VERTEX_ATTRIB_FORMAT_CONST
);
1180 if (nvc0
->state
.instance_elts
) {
1181 nvc0
->state
.instance_elts
= 0;
1182 BEGIN_NVC0(push
, NVC0_3D(MACRO_VERTEX_ARRAY_PER_INSTANCE
), 2);
1183 PUSH_DATA (push
, n
);
1184 PUSH_DATA (push
, 0);
1186 nvc0
->state
.num_vtxelts
= 2;
1188 for (i
= 0; i
< info
->dst
.box
.depth
; ++i
, z
+= dz
) {
1189 if (info
->dst
.box
.z
+ i
) {
1190 BEGIN_NVC0(push
, NVC0_3D(LAYER
), 1);
1191 PUSH_DATA (push
, info
->dst
.box
.z
+ i
);
1194 *(vbuf
++) = fui(0.0f
);
1195 *(vbuf
++) = fui(0.0f
);
1196 *(vbuf
++) = fui(x0
);
1197 *(vbuf
++) = fui(y0
);
1200 *(vbuf
++) = fui(16384 << nv50_miptree(dst
)->ms_x
);
1201 *(vbuf
++) = fui(0.0f
);
1202 *(vbuf
++) = fui(x1
);
1203 *(vbuf
++) = fui(y0
);
1206 *(vbuf
++) = fui(0.0f
);
1207 *(vbuf
++) = fui(16384 << nv50_miptree(dst
)->ms_y
);
1208 *(vbuf
++) = fui(x0
);
1209 *(vbuf
++) = fui(y1
);
1212 IMMED_NVC0(push
, NVC0_3D(VERTEX_BEGIN_GL
),
1213 NVC0_3D_VERTEX_BEGIN_GL_PRIMITIVE_TRIANGLES
);
1214 BEGIN_NVC0(push
, NVC0_3D(VERTEX_BUFFER_FIRST
), 2);
1215 PUSH_DATA (push
, i
* 3);
1216 PUSH_DATA (push
, 3);
1217 IMMED_NVC0(push
, NVC0_3D(VERTEX_END_GL
), 0);
1219 if (info
->dst
.box
.z
+ info
->dst
.box
.depth
- 1)
1220 IMMED_NVC0(push
, NVC0_3D(LAYER
), 0);
1222 nvc0_blitctx_post_blit(blit
);
1224 /* restore viewport transform */
1225 IMMED_NVC0(push
, NVC0_3D(VIEWPORT_TRANSFORM_EN
), 1);
1229 nvc0_blit_eng2d(struct nvc0_context
*nvc0
, const struct pipe_blit_info
*info
)
1231 struct nouveau_pushbuf
*push
= nvc0
->base
.pushbuf
;
1232 struct nv50_miptree
*dst
= nv50_miptree(info
->dst
.resource
);
1233 struct nv50_miptree
*src
= nv50_miptree(info
->src
.resource
);
1234 const int32_t srcx_adj
= info
->src
.box
.width
< 0 ? -1 : 0;
1235 const int32_t srcy_adj
= info
->src
.box
.height
< 0 ? -1 : 0;
1236 const int dz
= info
->dst
.box
.z
;
1237 const int sz
= info
->src
.box
.z
;
1238 uint32_t dstw
, dsth
;
1241 int64_t du_dx
, dv_dy
;
1244 uint32_t mask
= nv50_blit_eng2d_get_mask(info
);
1247 mode
= nv50_blit_get_filter(info
) ?
1248 NV50_2D_BLIT_CONTROL_FILTER_BILINEAR
:
1249 NV50_2D_BLIT_CONTROL_FILTER_POINT_SAMPLE
;
1250 mode
|= (src
->base
.base
.nr_samples
> dst
->base
.base
.nr_samples
) ?
1251 NV50_2D_BLIT_CONTROL_ORIGIN_CORNER
: NV50_2D_BLIT_CONTROL_ORIGIN_CENTER
;
1253 du_dx
= ((int64_t)info
->src
.box
.width
<< 32) / info
->dst
.box
.width
;
1254 dv_dy
= ((int64_t)info
->src
.box
.height
<< 32) / info
->dst
.box
.height
;
1256 b
= info
->dst
.format
== info
->src
.format
;
1257 nvc0_2d_texture_set(push
, 1, dst
, info
->dst
.level
, dz
, info
->dst
.format
, b
);
1258 nvc0_2d_texture_set(push
, 0, src
, info
->src
.level
, sz
, info
->src
.format
, b
);
1260 if (info
->scissor_enable
) {
1261 BEGIN_NVC0(push
, NVC0_2D(CLIP_X
), 5);
1262 PUSH_DATA (push
, info
->scissor
.minx
<< dst
->ms_x
);
1263 PUSH_DATA (push
, info
->scissor
.miny
<< dst
->ms_y
);
1264 PUSH_DATA (push
, (info
->scissor
.maxx
- info
->scissor
.minx
) << dst
->ms_x
);
1265 PUSH_DATA (push
, (info
->scissor
.maxy
- info
->scissor
.miny
) << dst
->ms_y
);
1266 PUSH_DATA (push
, 1); /* enable */
1269 if (nvc0
->cond_query
&& info
->render_condition_enable
)
1270 IMMED_NVC0(push
, NVC0_2D(COND_MODE
), nvc0
->cond_condmode
);
1272 if (mask
!= 0xffffffff) {
1273 IMMED_NVC0(push
, NVC0_2D(ROP
), 0xca); /* DPSDxax */
1274 IMMED_NVC0(push
, NVC0_2D(PATTERN_COLOR_FORMAT
),
1275 NV50_2D_PATTERN_COLOR_FORMAT_A8R8G8B8
);
1276 BEGIN_NVC0(push
, NVC0_2D(PATTERN_BITMAP_COLOR(0)), 4);
1277 PUSH_DATA (push
, 0x00000000);
1278 PUSH_DATA (push
, mask
);
1279 PUSH_DATA (push
, 0xffffffff);
1280 PUSH_DATA (push
, 0xffffffff);
1281 IMMED_NVC0(push
, NVC0_2D(OPERATION
), NV50_2D_OPERATION_ROP
);
1283 if (info
->src
.format
!= info
->dst
.format
) {
1284 if (info
->src
.format
== PIPE_FORMAT_R8_UNORM
||
1285 info
->src
.format
== PIPE_FORMAT_R8_SNORM
||
1286 info
->src
.format
== PIPE_FORMAT_R16_UNORM
||
1287 info
->src
.format
== PIPE_FORMAT_R16_SNORM
||
1288 info
->src
.format
== PIPE_FORMAT_R16_FLOAT
||
1289 info
->src
.format
== PIPE_FORMAT_R32_FLOAT
) {
1290 mask
= 0xffff0000; /* also makes condition for OPERATION reset true */
1291 BEGIN_NVC0(push
, NVC0_2D(BETA4
), 2);
1292 PUSH_DATA (push
, mask
);
1293 PUSH_DATA (push
, NV50_2D_OPERATION_SRCCOPY_PREMULT
);
1295 if (info
->src
.format
== PIPE_FORMAT_A8_UNORM
) {
1297 BEGIN_NVC0(push
, NVC0_2D(BETA4
), 2);
1298 PUSH_DATA (push
, mask
);
1299 PUSH_DATA (push
, NV50_2D_OPERATION_SRCCOPY_PREMULT
);
1303 if (src
->ms_x
> dst
->ms_x
|| src
->ms_y
> dst
->ms_y
) {
1304 /* ms_x is always >= ms_y */
1305 du_dx
<<= src
->ms_x
- dst
->ms_x
;
1306 dv_dy
<<= src
->ms_y
- dst
->ms_y
;
1308 du_dx
>>= dst
->ms_x
- src
->ms_x
;
1309 dv_dy
>>= dst
->ms_y
- src
->ms_y
;
1312 srcx
= (int64_t)(info
->src
.box
.x
+ srcx_adj
) << (src
->ms_x
+ 32);
1313 srcy
= (int64_t)(info
->src
.box
.y
+ srcy_adj
) << (src
->ms_y
+ 32);
1315 if (src
->base
.base
.nr_samples
> dst
->base
.base
.nr_samples
) {
1316 /* center src coorinates for proper MS resolve filtering */
1317 srcx
+= (int64_t)1 << (src
->ms_x
+ 31);
1318 srcy
+= (int64_t)1 << (src
->ms_y
+ 31);
1321 dstx
= info
->dst
.box
.x
<< dst
->ms_x
;
1322 dsty
= info
->dst
.box
.y
<< dst
->ms_y
;
1324 dstw
= info
->dst
.box
.width
<< dst
->ms_x
;
1325 dsth
= info
->dst
.box
.height
<< dst
->ms_y
;
1329 srcx
-= du_dx
* dstx
;
1334 srcy
-= dv_dy
* dsty
;
1338 IMMED_NVC0(push
, NVC0_2D(BLIT_CONTROL
), mode
);
1339 BEGIN_NVC0(push
, NVC0_2D(BLIT_DST_X
), 4);
1340 PUSH_DATA (push
, dstx
);
1341 PUSH_DATA (push
, dsty
);
1342 PUSH_DATA (push
, dstw
);
1343 PUSH_DATA (push
, dsth
);
1344 BEGIN_NVC0(push
, NVC0_2D(BLIT_DU_DX_FRACT
), 4);
1345 PUSH_DATA (push
, du_dx
);
1346 PUSH_DATA (push
, du_dx
>> 32);
1347 PUSH_DATA (push
, dv_dy
);
1348 PUSH_DATA (push
, dv_dy
>> 32);
1350 BCTX_REFN(nvc0
->bufctx
, 2D
, &dst
->base
, WR
);
1351 BCTX_REFN(nvc0
->bufctx
, 2D
, &src
->base
, RD
);
1352 nouveau_pushbuf_bufctx(nvc0
->base
.pushbuf
, nvc0
->bufctx
);
1353 if (nouveau_pushbuf_validate(nvc0
->base
.pushbuf
))
1356 for (i
= 0; i
< info
->dst
.box
.depth
; ++i
) {
1358 /* no scaling in z-direction possible for eng2d blits */
1359 if (dst
->layout_3d
) {
1360 BEGIN_NVC0(push
, NVC0_2D(DST_LAYER
), 1);
1361 PUSH_DATA (push
, info
->dst
.box
.z
+ i
);
1363 const unsigned z
= info
->dst
.box
.z
+ i
;
1364 const uint64_t address
= dst
->base
.address
+
1365 dst
->level
[info
->dst
.level
].offset
+
1366 z
* dst
->layer_stride
;
1367 BEGIN_NVC0(push
, NVC0_2D(DST_ADDRESS_HIGH
), 2);
1368 PUSH_DATAh(push
, address
);
1369 PUSH_DATA (push
, address
);
1371 if (src
->layout_3d
) {
1372 /* not possible because of depth tiling */
1375 const unsigned z
= info
->src
.box
.z
+ i
;
1376 const uint64_t address
= src
->base
.address
+
1377 src
->level
[info
->src
.level
].offset
+
1378 z
* src
->layer_stride
;
1379 BEGIN_NVC0(push
, NVC0_2D(SRC_ADDRESS_HIGH
), 2);
1380 PUSH_DATAh(push
, address
);
1381 PUSH_DATA (push
, address
);
1383 BEGIN_NVC0(push
, NVC0_2D(BLIT_SRC_Y_INT
), 1); /* trigger */
1384 PUSH_DATA (push
, srcy
>> 32);
1386 BEGIN_NVC0(push
, NVC0_2D(BLIT_SRC_X_FRACT
), 4);
1387 PUSH_DATA (push
, srcx
);
1388 PUSH_DATA (push
, srcx
>> 32);
1389 PUSH_DATA (push
, srcy
);
1390 PUSH_DATA (push
, srcy
>> 32);
1393 nvc0_resource_validate(&dst
->base
, NOUVEAU_BO_WR
);
1394 nvc0_resource_validate(&src
->base
, NOUVEAU_BO_RD
);
1396 nouveau_bufctx_reset(nvc0
->bufctx
, NVC0_BIND_2D
);
1398 if (info
->scissor_enable
)
1399 IMMED_NVC0(push
, NVC0_2D(CLIP_ENABLE
), 0);
1400 if (mask
!= 0xffffffff)
1401 IMMED_NVC0(push
, NVC0_2D(OPERATION
), NV50_2D_OPERATION_SRCCOPY
);
1402 if (nvc0
->cond_query
&& info
->render_condition_enable
)
1403 IMMED_NVC0(push
, NVC0_2D(COND_MODE
), NV50_2D_COND_MODE_ALWAYS
);
1407 nvc0_blit(struct pipe_context
*pipe
, const struct pipe_blit_info
*info
)
1409 struct nvc0_context
*nvc0
= nvc0_context(pipe
);
1410 struct nouveau_pushbuf
*push
= nvc0
->base
.pushbuf
;
1413 if (util_format_is_depth_or_stencil(info
->dst
.resource
->format
)) {
1414 if (!(info
->mask
& PIPE_MASK_ZS
))
1416 if (info
->dst
.resource
->format
== PIPE_FORMAT_Z32_FLOAT
||
1417 info
->dst
.resource
->format
== PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
)
1419 if (info
->filter
!= PIPE_TEX_FILTER_NEAREST
)
1422 if (!(info
->mask
& PIPE_MASK_RGBA
))
1424 if (info
->mask
!= PIPE_MASK_RGBA
)
1428 if (nv50_miptree(info
->src
.resource
)->layout_3d
) {
1431 if (info
->src
.box
.depth
!= info
->dst
.box
.depth
) {
1433 debug_printf("blit: cannot filter array or cube textures in z direction");
1436 if (!eng3d
&& info
->dst
.format
!= info
->src
.format
) {
1437 if (!nv50_2d_dst_format_faithful(info
->dst
.format
)) {
1440 if (!nv50_2d_src_format_faithful(info
->src
.format
)) {
1441 if (!util_format_is_luminance(info
->src
.format
)) {
1442 if (!nv50_2d_dst_format_ops_supported(info
->dst
.format
))
1445 if (util_format_is_intensity(info
->src
.format
))
1446 eng3d
= info
->src
.format
!= PIPE_FORMAT_I8_UNORM
;
1448 if (util_format_is_alpha(info
->src
.format
))
1449 eng3d
= info
->src
.format
!= PIPE_FORMAT_A8_UNORM
;
1451 eng3d
= !nv50_2d_format_supported(info
->src
.format
);
1454 if (util_format_is_luminance_alpha(info
->src
.format
))
1458 if (info
->src
.resource
->nr_samples
== 8 &&
1459 info
->dst
.resource
->nr_samples
<= 1)
1462 /* FIXME: can't make this work with eng2d anymore, at least not on nv50 */
1463 if (info
->src
.resource
->nr_samples
> 1 ||
1464 info
->dst
.resource
->nr_samples
> 1)
1467 /* FIXME: find correct src coordinates adjustments */
1468 if ((info
->src
.box
.width
!= info
->dst
.box
.width
&&
1469 info
->src
.box
.width
!= -info
->dst
.box
.width
) ||
1470 (info
->src
.box
.height
!= info
->dst
.box
.height
&&
1471 info
->src
.box
.height
!= -info
->dst
.box
.height
))
1474 if (nvc0
->screen
->num_occlusion_queries_active
)
1475 IMMED_NVC0(push
, NVC0_3D(SAMPLECNT_ENABLE
), 0);
1478 nvc0_blit_eng2d(nvc0
, info
);
1480 nvc0_blit_3d(nvc0
, info
);
1482 if (nvc0
->screen
->num_occlusion_queries_active
)
1483 IMMED_NVC0(push
, NVC0_3D(SAMPLECNT_ENABLE
), 1);
1485 NOUVEAU_DRV_STAT(&nvc0
->screen
->base
, tex_blit_count
, 1);
1489 nvc0_flush_resource(struct pipe_context
*ctx
,
1490 struct pipe_resource
*resource
)
1495 nvc0_blitter_create(struct nvc0_screen
*screen
)
1497 screen
->blitter
= CALLOC_STRUCT(nvc0_blitter
);
1498 if (!screen
->blitter
) {
1499 NOUVEAU_ERR("failed to allocate blitter struct\n");
1502 screen
->blitter
->screen
= screen
;
1504 pipe_mutex_init(screen
->blitter
->mutex
);
1506 nvc0_blitter_make_vp(screen
->blitter
);
1507 nvc0_blitter_make_sampler(screen
->blitter
);
1513 nvc0_blitter_destroy(struct nvc0_screen
*screen
)
1515 struct nvc0_blitter
*blitter
= screen
->blitter
;
1518 for (i
= 0; i
< NV50_BLIT_MAX_TEXTURE_TYPES
; ++i
) {
1519 for (m
= 0; m
< NV50_BLIT_MODES
; ++m
) {
1520 struct nvc0_program
*prog
= blitter
->fp
[i
][m
];
1522 nvc0_program_destroy(NULL
, prog
);
1523 FREE((void *)prog
->pipe
.tokens
);
1533 nvc0_blitctx_create(struct nvc0_context
*nvc0
)
1535 nvc0
->blit
= CALLOC_STRUCT(nvc0_blitctx
);
1537 NOUVEAU_ERR("failed to allocate blit context\n");
1541 nvc0
->blit
->nvc0
= nvc0
;
1543 nvc0
->blit
->rast
.pipe
.half_pixel_center
= 1;
1549 nvc0_blitctx_destroy(struct nvc0_context
*nvc0
)
1555 nvc0_init_surface_functions(struct nvc0_context
*nvc0
)
1557 struct pipe_context
*pipe
= &nvc0
->base
.pipe
;
1559 pipe
->resource_copy_region
= nvc0_resource_copy_region
;
1560 pipe
->blit
= nvc0_blit
;
1561 pipe
->flush_resource
= nvc0_flush_resource
;
1562 pipe
->clear_render_target
= nvc0_clear_render_target
;
1563 pipe
->clear_depth_stencil
= nvc0_clear_depth_stencil
;
1564 pipe
->clear_texture
= nv50_clear_texture
;
1565 pipe
->clear_buffer
= nvc0_clear_buffer
;