X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fgallium%2Fdrivers%2Fnouveau%2Fnouveau_video.c;h=95d8866bae895d523d973b7dd9469fd6bec79f41;hb=d2de40f07e61fdee168a54ca09fd6c3ac0dac6d7;hp=06fbde46cc0be5ddd64b1db32a2e517396085df3;hpb=8abbdb8865890e1a39ebbbfae38422014f80072a;p=mesa.git diff --git a/src/gallium/drivers/nouveau/nouveau_video.c b/src/gallium/drivers/nouveau/nouveau_video.c index 06fbde46cc0..95d8866bae8 100644 --- a/src/gallium/drivers/nouveau/nouveau_video.c +++ b/src/gallium/drivers/nouveau/nouveau_video.c @@ -14,10 +14,10 @@ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF - * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. */ #include "vl/vl_decoder.h" @@ -27,38 +27,23 @@ #include "nouveau_context.h" #include "nouveau_video.h" -#include "nvfx/nvfx_context.h" -#include "nvfx/nvfx_resource.h" -#include "nouveau/nouveau_bo.h" -#include "nouveau/nouveau_buffer.h" +#include "nouveau_buffer.h" #include "util/u_video.h" #include "util/u_format.h" #include "util/u_sampler.h" -#include "nouveau/nouveau_device.h" -#include "nouveau_winsys.h" - -static bool -nouveau_video_is_nvfx(struct nouveau_decoder *dec) { - if (dec->screen->device->chipset < 0x50) - return true; - if (dec->screen->device->chipset >= 0x60 && dec->screen->device->chipset < 0x70) - return true; - return false; -} static int nouveau_vpe_init(struct nouveau_decoder *dec) { int ret; if (dec->cmds) return 0; - ret = nouveau_bo_map(dec->cmd_bo, NOUVEAU_BO_RDWR); + ret = nouveau_bo_map(dec->cmd_bo, NOUVEAU_BO_RDWR, dec->client); if (ret) { debug_printf("Mapping cmd bo: %s\n", strerror(-ret)); return ret; } - ret = nouveau_bo_map(dec->data_bo, NOUVEAU_BO_RDWR); + ret = nouveau_bo_map(dec->data_bo, NOUVEAU_BO_RDWR, dec->client); if (ret) { - nouveau_bo_unmap(dec->cmd_bo); debug_printf("Mapping data bo: %s\n", strerror(-ret)); return ret; } @@ -69,39 +54,45 @@ nouveau_vpe_init(struct nouveau_decoder *dec) { static void nouveau_vpe_synch(struct nouveau_decoder *dec) { - struct nouveau_channel *chan = dec->screen->channel; + struct nouveau_pushbuf *push = dec->push; #if 0 if (dec->fence_map) { - BEGIN_RING(chan, dec->mpeg, NV84_MPEG_QUERY_COUNTER, 1); - OUT_RING(chan, ++dec->fence_seq); - FIRE_RING(chan); + BEGIN_NV04(push, NV84_MPEG(QUERY_COUNTER), 1); + PUSH_DATA (push, ++dec->fence_seq); + PUSH_KICK (push); while (dec->fence_map[0] != dec->fence_seq) usleep(1000); } else #endif - FIRE_RING(chan); + PUSH_KICK(push); } static void nouveau_vpe_fini(struct nouveau_decoder *dec) { - struct nouveau_channel *chan = dec->screen->channel; + struct nouveau_pushbuf *push = dec->push; if (!dec->cmds) return; - nouveau_bo_unmap(dec->data_bo); - nouveau_bo_unmap(dec->cmd_bo); + nouveau_pushbuf_space(push, 16, 2, 0); + nouveau_bufctx_reset(dec->bufctx, NV31_VIDEO_BIND_CMD); - MARK_RING(chan, 8, 2); - BEGIN_RING(chan, dec->mpeg, NV31_MPEG_CMD_OFFSET, 2); - OUT_RELOCl(chan, dec->cmd_bo, 0, NOUVEAU_BO_RD|NOUVEAU_BO_GART); - OUT_RING(chan, dec->ofs * 4); +#define BCTX_ARGS dec->bufctx, NV31_VIDEO_BIND_CMD, NOUVEAU_BO_RD - BEGIN_RING(chan, dec->mpeg, NV31_MPEG_DATA_OFFSET, 2); - OUT_RELOCl(chan, dec->data_bo, 0, NOUVEAU_BO_RD|NOUVEAU_BO_GART); - OUT_RING(chan, dec->data_pos * 4); + BEGIN_NV04(push, NV31_MPEG(CMD_OFFSET), 2); + PUSH_MTHDl(push, NV31_MPEG(CMD_OFFSET), dec->cmd_bo, 0, BCTX_ARGS); + PUSH_DATA (push, dec->ofs * 4); + + BEGIN_NV04(push, NV31_MPEG(DATA_OFFSET), 2); + PUSH_MTHDl(push, NV31_MPEG(DATA_OFFSET), dec->data_bo, 0, BCTX_ARGS); + PUSH_DATA (push, dec->data_pos * 4); + +#undef BCTX_ARGS + + if (unlikely(nouveau_pushbuf_validate(dec->push))) + return; - BEGIN_RING(chan, dec->mpeg, NV31_MPEG_EXEC, 1); - OUT_RING(chan, 1); + BEGIN_NV04(push, NV31_MPEG(EXEC), 1); + PUSH_DATA (push, 1); nouveau_vpe_synch(dec); dec->ofs = dec->data_pos = dec->num_surfaces = 0; @@ -109,7 +100,7 @@ nouveau_vpe_fini(struct nouveau_decoder *dec) { dec->current = dec->future = dec->past = 8; } -static INLINE void +static inline void nouveau_vpe_mb_dct_blocks(struct nouveau_decoder *dec, const struct pipe_mpeg12_macroblock *mb) { int cbb; @@ -117,21 +108,10 @@ nouveau_vpe_mb_dct_blocks(struct nouveau_decoder *dec, const struct pipe_mpeg12_ short *db = mb->blocks; for (cbb = 0x20; cbb > 0; cbb >>= 1) { if (cbb & cbp) { - static const int lookup[64] = { - 0, 1, 8,16, 9, 2, 3,10, - 17,24,32,25,18,11, 4, 5, - 12,19,26,33,40,48,41,34, - 27,20,13, 6, 7,14,21,28, - 35,42,49,56,57,50,43,36, - 29,22,15,23,30,37,44,51, - 58,59,52,45,38,31,39,46, - 53,60,61,54,47,55,62,63 - }; - int i, j = 0, found = 0; + int i, found = 0; for (i = 0; i < 64; ++i) { - if (!db[lookup[i]]) { j += 2; continue; } - dec->data[dec->data_pos++] = (db[lookup[i]] << 16) | j; - j = 0; + if (!db[i]) continue; + dec->data[dec->data_pos++] = (db[i] << 16) | (i * 2); found = 1; } if (found) @@ -145,7 +125,7 @@ nouveau_vpe_mb_dct_blocks(struct nouveau_decoder *dec, const struct pipe_mpeg12_ } } -static INLINE void +static inline void nouveau_vpe_mb_data_blocks(struct nouveau_decoder *dec, const struct pipe_mpeg12_macroblock *mb) { int cbb; @@ -163,7 +143,7 @@ nouveau_vpe_mb_data_blocks(struct nouveau_decoder *dec, const struct pipe_mpeg12 } } -static INLINE void +static inline void nouveau_vpe_mb_dct_header(struct nouveau_decoder *dec, const struct pipe_mpeg12_macroblock *mb, bool luma) @@ -207,7 +187,7 @@ nouveau_vpe_mb_dct_header(struct nouveau_decoder *dec, x | (y << NV17_MPEG_CMD_MB_COORDS_Y__SHIFT)); } -static INLINE unsigned int +static inline unsigned int nouveau_vpe_mb_mv_flags(bool luma, int mv_h, int mv_v, bool forward, bool first, bool vert) { unsigned mc_header = 0; @@ -248,7 +228,7 @@ static int div_up(int val, int mult) { return val / mult; } -static INLINE void +static inline void nouveau_vpe_mb_mv(struct nouveau_decoder *dec, unsigned mc_header, bool luma, bool frame, bool forward, bool vert, int x, int y, const short motions[2], @@ -316,16 +296,16 @@ nouveau_vpe_mb_mv_header(struct nouveau_decoder *dec, case PIPE_MPEG12_MO_TYPE_DUAL_PRIME: { base = NV17_MPEG_CMD_CHROMA_MV_HEADER_COUNT_2; if (forward) { - nouveau_vpe_mb_mv(dec, base, luma, frame, TRUE, FALSE, - x, y, mb->PMV[0][0], dec->past, TRUE); - nouveau_vpe_mb_mv(dec, base, luma, frame, TRUE, TRUE, - x, y2, mb->PMV[0][0], dec->past, FALSE); + nouveau_vpe_mb_mv(dec, base, luma, frame, true, false, + x, y, mb->PMV[0][0], dec->past, true); + nouveau_vpe_mb_mv(dec, base, luma, frame, true, true, + x, y2, mb->PMV[0][0], dec->past, false); } if (backward && forward) { - nouveau_vpe_mb_mv(dec, base, luma, frame, !forward, TRUE, - x, y, mb->PMV[1][0], dec->future, TRUE); - nouveau_vpe_mb_mv(dec, base, luma, frame, !forward, FALSE, - x, y2, mb->PMV[1][1], dec->future, FALSE); + nouveau_vpe_mb_mv(dec, base, luma, frame, !forward, true, + x, y, mb->PMV[1][0], dec->future, true); + nouveau_vpe_mb_mv(dec, base, luma, frame, !forward, false, + x, y2, mb->PMV[1][1], dec->future, false); } else assert(!backward); break; } @@ -340,13 +320,13 @@ nouveau_vpe_mb_mv_header(struct nouveau_decoder *dec, if (frame) base |= NV17_MPEG_CMD_CHROMA_MV_HEADER_TYPE_FRAME; if (forward) - nouveau_vpe_mb_mv(dec, base, luma, frame, TRUE, + nouveau_vpe_mb_mv(dec, base, luma, frame, true, dec->picture_structure != PIPE_MPEG12_PICTURE_STRUCTURE_FIELD_TOP, - x, y, mb->PMV[0][0], dec->past, TRUE); + x, y, mb->PMV[0][0], dec->past, true); if (backward && forward) - nouveau_vpe_mb_mv(dec, base, luma, frame, FALSE, + nouveau_vpe_mb_mv(dec, base, luma, frame, false, dec->picture_structure == PIPE_MPEG12_PICTURE_STRUCTURE_FIELD_TOP, - x, y, mb->PMV[0][1], dec->future, TRUE); + x, y, mb->PMV[0][1], dec->future, true); else assert(!backward); break; } @@ -361,11 +341,11 @@ mv1: base |= NV17_MPEG_CMD_CHROMA_MV_HEADER_TYPE_FRAME; /* frame 16x16 */ if (forward) - nouveau_vpe_mb_mv(dec, base, luma, frame, TRUE, FALSE, - x, y, mb->PMV[0][0], dec->past, TRUE); + nouveau_vpe_mb_mv(dec, base, luma, frame, true, false, + x, y, mb->PMV[0][0], dec->past, true); if (backward) - nouveau_vpe_mb_mv(dec, base, luma, frame, !forward, FALSE, - x, y, mb->PMV[0][1], dec->future, TRUE); + nouveau_vpe_mb_mv(dec, base, luma, frame, !forward, false, + x, y, mb->PMV[0][1], dec->future, true); return; mv2: @@ -373,20 +353,20 @@ mv2: if (!frame) base |= NV17_MPEG_CMD_CHROMA_MV_HEADER_MV_SPLIT_HALF_MB; if (forward) { - nouveau_vpe_mb_mv(dec, base, luma, frame, TRUE, + nouveau_vpe_mb_mv(dec, base, luma, frame, true, mb->motion_vertical_field_select & PIPE_MPEG12_FS_FIRST_FORWARD, - x, y, mb->PMV[0][0], dec->past, TRUE); - nouveau_vpe_mb_mv(dec, base, luma, frame, TRUE, + x, y, mb->PMV[0][0], dec->past, true); + nouveau_vpe_mb_mv(dec, base, luma, frame, true, mb->motion_vertical_field_select & PIPE_MPEG12_FS_SECOND_FORWARD, - x, y2, mb->PMV[1][0], dec->past, FALSE); + x, y2, mb->PMV[1][0], dec->past, false); } if (backward) { nouveau_vpe_mb_mv(dec, base, luma, frame, !forward, mb->motion_vertical_field_select & PIPE_MPEG12_FS_FIRST_BACKWARD, - x, y, mb->PMV[0][1], dec->future, TRUE); + x, y, mb->PMV[0][1], dec->future, true); nouveau_vpe_mb_mv(dec, base, luma, frame, !forward, mb->motion_vertical_field_select & PIPE_MPEG12_FS_SECOND_BACKWARD, - x, y2, mb->PMV[1][1], dec->future, FALSE); + x, y2, mb->PMV[1][1], dec->future, false); } } @@ -395,12 +375,12 @@ nouveau_decoder_surface_index(struct nouveau_decoder *dec, struct pipe_video_buffer *buffer) { struct nouveau_video_buffer *buf = (struct nouveau_video_buffer *)buffer; - struct nouveau_channel *chan = dec->screen->channel; - struct nouveau_bo *bo_y, *bo_c; + struct nouveau_pushbuf *push = dec->push; + struct nouveau_bo *bo_y = nv04_resource(buf->resources[0])->bo; + struct nouveau_bo *bo_c = nv04_resource(buf->resources[1])->bo; + unsigned i; - if (!buf) - return 8; for (i = 0; i < dec->num_surfaces; ++i) { if (dec->surfaces[i] == buf) return i; @@ -409,29 +389,26 @@ nouveau_decoder_surface_index(struct nouveau_decoder *dec, dec->surfaces[i] = buf; dec->num_surfaces++; - if (nouveau_video_is_nvfx(dec)) { - bo_y = ((struct nvfx_resource *)buf->resources[0])->bo; - bo_c = ((struct nvfx_resource *)buf->resources[1])->bo; - } else { - bo_y = ((struct nv04_resource *)buf->resources[0])->bo; - bo_c = ((struct nv04_resource *)buf->resources[1])->bo; - } - MARK_RING(chan, 3, 2); - BEGIN_RING(chan, dec->mpeg, NV31_MPEG_IMAGE_Y_OFFSET(i), 2); - OUT_RELOCl(chan, bo_y, 0, NOUVEAU_BO_RDWR); - OUT_RELOCl(chan, bo_c, 0, NOUVEAU_BO_RDWR); + nouveau_bufctx_reset(dec->bufctx, NV31_VIDEO_BIND_IMG(i)); + +#define BCTX_ARGS dec->bufctx, NV31_VIDEO_BIND_IMG(i), NOUVEAU_BO_RDWR + BEGIN_NV04(push, NV31_MPEG(IMAGE_Y_OFFSET(i)), 2); + PUSH_MTHDl(push, NV31_MPEG(IMAGE_Y_OFFSET(i)), bo_y, 0, BCTX_ARGS); + PUSH_MTHDl(push, NV31_MPEG(IMAGE_C_OFFSET(i)), bo_c, 0, BCTX_ARGS); +#undef BCTX_ARGS + return i; } static void -nouveau_decoder_begin_frame(struct pipe_video_decoder *decoder, +nouveau_decoder_begin_frame(struct pipe_video_codec *decoder, struct pipe_video_buffer *target, struct pipe_picture_desc *picture) { } static void -nouveau_decoder_decode_macroblock(struct pipe_video_decoder *decoder, +nouveau_decoder_decode_macroblock(struct pipe_video_codec *decoder, struct pipe_video_buffer *target, struct pipe_picture_desc *picture, const struct pipe_macroblock *pipe_mb, @@ -453,17 +430,22 @@ nouveau_decoder_decode_macroblock(struct pipe_video_decoder *decoder, dec->past = nouveau_decoder_surface_index(dec, desc->ref[0]); if (nouveau_vpe_init(dec)) return; + + /* initialize scan order */ + nouveau_vpe_write(dec, 0x720000c0); + nouveau_vpe_write(dec, dec->data_pos); + mb = (const struct pipe_mpeg12_macroblock *)pipe_mb; for (i = 0; i < num_macroblocks; ++i, mb++) { if (mb->macroblock_type & PIPE_MPEG12_MB_TYPE_INTRA) { - nouveau_vpe_mb_dct_header(dec, mb, TRUE); - nouveau_vpe_mb_dct_header(dec, mb, FALSE); + nouveau_vpe_mb_dct_header(dec, mb, true); + nouveau_vpe_mb_dct_header(dec, mb, false); } else { - nouveau_vpe_mb_mv_header(dec, mb, TRUE); - nouveau_vpe_mb_dct_header(dec, mb, TRUE); + nouveau_vpe_mb_mv_header(dec, mb, true); + nouveau_vpe_mb_dct_header(dec, mb, true); - nouveau_vpe_mb_mv_header(dec, mb, FALSE); - nouveau_vpe_mb_dct_header(dec, mb, FALSE); + nouveau_vpe_mb_mv_header(dec, mb, false); + nouveau_vpe_mb_dct_header(dec, mb, false); } if (dec->base.entrypoint <= PIPE_VIDEO_ENTRYPOINT_IDCT) nouveau_vpe_mb_dct_blocks(dec, mb); @@ -473,14 +455,14 @@ nouveau_decoder_decode_macroblock(struct pipe_video_decoder *decoder, } static void -nouveau_decoder_end_frame(struct pipe_video_decoder *decoder, +nouveau_decoder_end_frame(struct pipe_video_codec *decoder, struct pipe_video_buffer *target, struct pipe_picture_desc *picture) { } static void -nouveau_decoder_flush(struct pipe_video_decoder *decoder) +nouveau_decoder_flush(struct pipe_video_codec *decoder) { struct nouveau_decoder *dec = (struct nouveau_decoder *)decoder; if (dec->ofs) @@ -488,133 +470,158 @@ nouveau_decoder_flush(struct pipe_video_decoder *decoder) } static void -nouveau_decoder_destroy(struct pipe_video_decoder *decoder) +nouveau_decoder_destroy(struct pipe_video_codec *decoder) { struct nouveau_decoder *dec = (struct nouveau_decoder*)decoder; - if (dec->cmds) { - nouveau_bo_unmap(dec->data_bo); - nouveau_bo_unmap(dec->cmd_bo); - } - if (dec->data_bo) nouveau_bo_ref(NULL, &dec->data_bo); if (dec->cmd_bo) nouveau_bo_ref(NULL, &dec->cmd_bo); if (dec->fence_bo) nouveau_bo_ref(NULL, &dec->fence_bo); - nouveau_grobj_free(&dec->mpeg); + + nouveau_object_del(&dec->mpeg); + + if (dec->bufctx) + nouveau_bufctx_del(&dec->bufctx); + if (dec->push) + nouveau_pushbuf_del(&dec->push); + if (dec->client) + nouveau_client_del(&dec->client); + if (dec->chan) + nouveau_object_del(&dec->chan); + FREE(dec); } -static struct pipe_video_decoder * +static struct pipe_video_codec * nouveau_create_decoder(struct pipe_context *context, - struct nouveau_screen *screen, - enum pipe_video_profile profile, - enum pipe_video_entrypoint entrypoint, - enum pipe_video_chroma_format chroma_format, - unsigned width, unsigned height, - unsigned max_references, bool expect_chunked_decode) + const struct pipe_video_codec *templ, + struct nouveau_screen *screen) { - struct nouveau_channel *chan = screen->channel; - struct nouveau_grobj *mpeg = NULL; + struct nv04_fifo nv04_data = { .vram = 0xbeef0201, .gart = 0xbeef0202 }; + unsigned width = templ->width, height = templ->height; + struct nouveau_object *mpeg = NULL; struct nouveau_decoder *dec; + struct nouveau_pushbuf *push; int ret; bool is8274 = screen->device->chipset > 0x80; - debug_printf("Acceleration level: %s\n", entrypoint <= PIPE_VIDEO_ENTRYPOINT_BITSTREAM ? "bit": - entrypoint == PIPE_VIDEO_ENTRYPOINT_IDCT ? "IDCT" : "MC"); + debug_printf("Acceleration level: %s\n", templ->entrypoint <= PIPE_VIDEO_ENTRYPOINT_BITSTREAM ? "bit": + templ->entrypoint == PIPE_VIDEO_ENTRYPOINT_IDCT ? "IDCT" : "MC"); if (getenv("XVMC_VL")) goto vl; - if (u_reduce_video_profile(profile) != PIPE_VIDEO_CODEC_MPEG12) + if (u_reduce_video_profile(templ->profile) != PIPE_VIDEO_FORMAT_MPEG12) goto vl; if (screen->device->chipset >= 0x98 && screen->device->chipset != 0xa0) goto vl; + if (screen->device->chipset < 0x40) + goto vl; + + dec = CALLOC_STRUCT(nouveau_decoder); + if (!dec) + return NULL; + + ret = nouveau_object_new(&screen->device->object, 0, + NOUVEAU_FIFO_CHANNEL_CLASS, + &nv04_data, sizeof(nv04_data), &dec->chan); + if (ret) + goto fail; + ret = nouveau_client_new(screen->device, &dec->client); + if (ret) + goto fail; + ret = nouveau_pushbuf_new(dec->client, dec->chan, 2, 4096, 1, &dec->push); + if (ret) + goto fail; + ret = nouveau_bufctx_new(dec->client, NV31_VIDEO_BIND_COUNT, &dec->bufctx); + if (ret) + goto fail; + push = dec->push; width = align(width, 64); height = align(height, 64); if (is8274) - ret = nouveau_grobj_alloc(chan, 0xbeef8274, 0x8274, &mpeg); + ret = nouveau_object_new(dec->chan, 0xbeef8274, NV84_MPEG_CLASS, NULL, 0, + &mpeg); else - ret = nouveau_grobj_alloc(chan, 0xbeef8274, 0x3174, &mpeg); + ret = nouveau_object_new(dec->chan, 0xbeef3174, NV31_MPEG_CLASS, NULL, 0, + &mpeg); if (ret < 0) { debug_printf("Creation failed: %s (%i)\n", strerror(-ret), ret); - return NULL; - } - - dec = CALLOC_STRUCT(nouveau_decoder); - if (!dec) { - nouveau_grobj_free(&mpeg); goto fail; } + dec->mpeg = mpeg; + dec->base = *templ; dec->base.context = context; - dec->base.profile = profile; - dec->base.entrypoint = entrypoint; - dec->base.chroma_format = chroma_format; dec->base.width = width; dec->base.height = height; - dec->base.max_references = max_references; dec->base.destroy = nouveau_decoder_destroy; dec->base.begin_frame = nouveau_decoder_begin_frame; dec->base.decode_macroblock = nouveau_decoder_decode_macroblock; - dec->base.begin_frame = nouveau_decoder_end_frame; + dec->base.end_frame = nouveau_decoder_end_frame; dec->base.flush = nouveau_decoder_flush; dec->screen = screen; - ret = nouveau_bo_new(dec->screen->device, NOUVEAU_BO_GART, 0, 1024 * 1024, &dec->cmd_bo); + ret = nouveau_bo_new(dec->screen->device, NOUVEAU_BO_GART | NOUVEAU_BO_MAP, + 0, 1024 * 1024, NULL, &dec->cmd_bo); if (ret) goto fail; - ret = nouveau_bo_new(dec->screen->device, NOUVEAU_BO_GART, 0, width * height * 6, &dec->data_bo); + ret = nouveau_bo_new(dec->screen->device, NOUVEAU_BO_GART | NOUVEAU_BO_MAP, + 0, width * height * 6, NULL, &dec->data_bo); if (ret) goto fail; - ret = nouveau_bo_new(dec->screen->device, NOUVEAU_BO_GART|NOUVEAU_BO_MAP, 0, 4096, - &dec->fence_bo); + /* we don't need the fence, the kernel sync's for us */ +#if 0 + ret = nouveau_bo_new(dec->screen->device, NOUVEAU_BO_GART | NOUVEAU_BO_MAP, + 0, 4096, NULL, &dec->fence_bo); if (ret) goto fail; - nouveau_bo_map(dec->fence_bo, NOUVEAU_BO_RDWR); + nouveau_bo_map(dec->fence_bo, NOUVEAU_BO_RDWR, NULL); dec->fence_map = dec->fence_bo->map; - nouveau_bo_unmap(dec->fence_bo); dec->fence_map[0] = 0; +#endif - if (is8274) - MARK_RING(chan, 25, 3); - else - MARK_RING(chan, 20, 2); + nouveau_pushbuf_bufctx(dec->push, dec->bufctx); + nouveau_pushbuf_space(push, 32, 4, 0); + + BEGIN_NV04(push, SUBC_MPEG(NV01_SUBCHAN_OBJECT), 1); + PUSH_DATA (push, dec->mpeg->handle); - BEGIN_RING(chan, mpeg, NV31_MPEG_DMA_CMD, 1); - OUT_RING(chan, chan->vram->handle); + BEGIN_NV04(push, NV31_MPEG(DMA_CMD), 1); + PUSH_DATA (push, nv04_data.gart); - BEGIN_RING(chan, mpeg, NV31_MPEG_DMA_DATA, 1); - OUT_RING(chan, chan->vram->handle); + BEGIN_NV04(push, NV31_MPEG(DMA_DATA), 1); + PUSH_DATA (push, nv04_data.gart); - BEGIN_RING(chan, mpeg, NV31_MPEG_DMA_IMAGE, 1); - OUT_RING(chan, chan->vram->handle); + BEGIN_NV04(push, NV31_MPEG(DMA_IMAGE), 1); + PUSH_DATA (push, nv04_data.vram); - BEGIN_RING(chan, mpeg, NV31_MPEG_PITCH, 2); - OUT_RING(chan, width | NV31_MPEG_PITCH_UNK); - OUT_RING(chan, (height << NV31_MPEG_SIZE_H__SHIFT) | width); + BEGIN_NV04(push, NV31_MPEG(PITCH), 2); + PUSH_DATA (push, width | NV31_MPEG_PITCH_UNK); + PUSH_DATA (push, (height << NV31_MPEG_SIZE_H__SHIFT) | width); - BEGIN_RING(chan, mpeg, NV31_MPEG_FORMAT, 2); - OUT_RING(chan, 0); - switch (entrypoint) { - case PIPE_VIDEO_ENTRYPOINT_BITSTREAM: OUT_RING(chan, 0x100); break; - case PIPE_VIDEO_ENTRYPOINT_IDCT: OUT_RING(chan, 1); break; - case PIPE_VIDEO_ENTRYPOINT_MC: OUT_RING(chan, 0); break; + BEGIN_NV04(push, NV31_MPEG(FORMAT), 2); + PUSH_DATA (push, 0); + switch (templ->entrypoint) { + case PIPE_VIDEO_ENTRYPOINT_IDCT: PUSH_DATA (push, 1); break; + case PIPE_VIDEO_ENTRYPOINT_MC: PUSH_DATA (push, 0); break; default: assert(0); } if (is8274) { - BEGIN_RING(chan, mpeg, NV84_MPEG_DMA_QUERY, 1); - OUT_RING(chan, chan->vram->handle); - - BEGIN_RING(chan, mpeg, NV84_MPEG_QUERY_OFFSET, 2); - OUT_RELOCl(chan, dec->fence_bo, 0, NOUVEAU_BO_WR|NOUVEAU_BO_GART); - OUT_RING(chan, dec->fence_seq); + BEGIN_NV04(push, NV84_MPEG(DMA_QUERY), 1); + PUSH_DATA (push, nv04_data.vram); +#if 0 + BEGIN_NV04(push, NV84_MPEG(QUERY_OFFSET), 2); + PUSH_DATA (push, dec->fence_bo->offset); + PUSH_DATA (push, dec->fence_seq); +#endif } ret = nouveau_vpe_init(dec); @@ -629,9 +636,7 @@ fail: vl: debug_printf("Using g3dvl renderer\n"); - return vl_create_decoder(context, profile, entrypoint, - chroma_format, width, height, - max_references, expect_chunked_decode); + return vl_create_decoder(context, templ); } static struct pipe_sampler_view ** @@ -652,7 +657,7 @@ nouveau_video_buffer_sampler_view_planes(struct pipe_video_buffer *buffer) u_sampler_view_default_template(&sv_templ, buf->resources[i], buf->resources[i]->format); if (util_format_get_nr_components(buf->resources[i]->format) == 1) - sv_templ.swizzle_r = sv_templ.swizzle_g = sv_templ.swizzle_b = sv_templ.swizzle_a = PIPE_SWIZZLE_RED; + sv_templ.swizzle_r = sv_templ.swizzle_g = sv_templ.swizzle_b = sv_templ.swizzle_a = PIPE_SWIZZLE_X; buf->sampler_view_planes[i] = pipe->create_sampler_view(pipe, buf->resources[i], &sv_templ); if (!buf->sampler_view_planes[i]) @@ -690,8 +695,8 @@ nouveau_video_buffer_sampler_view_components(struct pipe_video_buffer *buffer) if (!buf->sampler_view_components[component]) { memset(&sv_templ, 0, sizeof(sv_templ)); u_sampler_view_default_template(&sv_templ, buf->resources[i], buf->resources[i]->format); - sv_templ.swizzle_r = sv_templ.swizzle_g = sv_templ.swizzle_b = PIPE_SWIZZLE_RED + j; - sv_templ.swizzle_a = PIPE_SWIZZLE_ONE; + sv_templ.swizzle_r = sv_templ.swizzle_g = sv_templ.swizzle_b = PIPE_SWIZZLE_X + j; + sv_templ.swizzle_a = PIPE_SWIZZLE_1; buf->sampler_view_components[component] = pipe->create_sampler_view(pipe, buf->resources[i], &sv_templ); if (!buf->sampler_view_components[component]) goto error; @@ -724,7 +729,6 @@ nouveau_video_buffer_surfaces(struct pipe_video_buffer *buffer) if (!buf->surfaces[i]) { memset(&surf_templ, 0, sizeof(surf_templ)); surf_templ.format = buf->resources[i]->format; - surf_templ.usage = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET; buf->surfaces[i] = pipe->create_surface(pipe, buf->resources[i], &surf_templ); if (!buf->surfaces[i]) goto error; @@ -774,7 +778,8 @@ nouveau_video_buffer_create(struct pipe_context *pipe, * and it only supports the NV12 format */ if (templat->buffer_format != PIPE_FORMAT_NV12 || getenv("XVMC_VL") || - (screen->device->chipset >= 0x98 && screen->device->chipset != 0xa0)) + (screen->device->chipset >= 0x98 && screen->device->chipset != 0xa0) || + screen->device->chipset < 0x40) return vl_video_buffer_create(pipe, templat); assert(templat->chroma_format == PIPE_VIDEO_CHROMA_FORMAT_420); @@ -791,6 +796,7 @@ nouveau_video_buffer_create(struct pipe_context *pipe, buffer->base.get_sampler_view_components = nouveau_video_buffer_sampler_view_components; buffer->base.get_surfaces = nouveau_video_buffer_surfaces; buffer->base.chroma_format = templat->chroma_format; + buffer->base.buffer_format = templat->buffer_format; buffer->base.width = width; buffer->base.height = height; buffer->num_planes = 2; @@ -803,7 +809,7 @@ nouveau_video_buffer_create(struct pipe_context *pipe, templ.depth0 = 1; templ.array_size = 1; templ.bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET; - templ.usage = PIPE_USAGE_STATIC; + templ.usage = PIPE_USAGE_DEFAULT; templ.flags = NOUVEAU_RESOURCE_FLAG_LINEAR; buffer->resources[0] = pipe->screen->resource_create(pipe->screen, &templ); @@ -825,11 +831,13 @@ error: static int nouveau_screen_get_video_param(struct pipe_screen *pscreen, enum pipe_video_profile profile, + enum pipe_video_entrypoint entrypoint, enum pipe_video_cap param) { switch (param) { case PIPE_VIDEO_CAP_SUPPORTED: - return vl_profile_supported(pscreen, profile); + return entrypoint >= PIPE_VIDEO_ENTRYPOINT_IDCT && + u_reduce_video_profile(profile) == PIPE_VIDEO_FORMAT_MPEG12; case PIPE_VIDEO_CAP_NPOT_TEXTURES: return 1; case PIPE_VIDEO_CAP_MAX_WIDTH: @@ -843,6 +851,8 @@ nouveau_screen_get_video_param(struct pipe_screen *pscreen, return false; case PIPE_VIDEO_CAP_SUPPORTS_PROGRESSIVE: return true; + case PIPE_VIDEO_CAP_MAX_LEVEL: + return vl_level_supported(pscreen, profile); default: debug_printf("unknown video param: %d\n", param); return 0; @@ -856,47 +866,12 @@ nouveau_screen_init_vdec(struct nouveau_screen *screen) screen->base.is_video_format_supported = vl_video_buffer_is_format_supported; } -static struct pipe_video_decoder * -nvfx_context_create_decoder(struct pipe_context *context, - enum pipe_video_profile profile, - enum pipe_video_entrypoint entrypoint, - enum pipe_video_chroma_format chroma_format, - unsigned width, unsigned height, - unsigned max_references, bool expect_chunked_decode) -{ - struct nouveau_screen *screen = &nvfx_context(context)->screen->base; - return nouveau_create_decoder(context, screen, profile, entrypoint, - chroma_format, width, height, - max_references, expect_chunked_decode); -} - -static struct pipe_video_buffer * -nvfx_context_video_buffer_create(struct pipe_context *pipe, - const struct pipe_video_buffer *templat) -{ - struct nouveau_screen *screen = &nvfx_context(pipe)->screen->base; - return nouveau_video_buffer_create(pipe, screen, templat); -} - -void -nvfx_context_init_vdec(struct nvfx_context *nv) -{ - nv->pipe.create_video_decoder = nvfx_context_create_decoder; - nv->pipe.create_video_buffer = nvfx_context_video_buffer_create; -} - -static struct pipe_video_decoder * +static struct pipe_video_codec * nouveau_context_create_decoder(struct pipe_context *context, - enum pipe_video_profile profile, - enum pipe_video_entrypoint entrypoint, - enum pipe_video_chroma_format chroma_format, - unsigned width, unsigned height, - unsigned max_references, bool expect_chunked_decode) + const struct pipe_video_codec *templ) { struct nouveau_screen *screen = nouveau_context(context)->screen; - return nouveau_create_decoder(context, screen, profile, entrypoint, - chroma_format, width, height, - max_references, expect_chunked_decode); + return nouveau_create_decoder(context, templ, screen); } static struct pipe_video_buffer * @@ -910,6 +885,6 @@ nouveau_context_video_buffer_create(struct pipe_context *pipe, void nouveau_context_init_vdec(struct nouveau_context *nv) { - nv->pipe.create_video_decoder = nouveau_context_create_decoder; + nv->pipe.create_video_codec = nouveau_context_create_decoder; nv->pipe.create_video_buffer = nouveau_context_video_buffer_create; }