aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/nouveau/nv50/nv98_video_ppp.c
blob: 6b0b7148dcb26573994e59e4c025dc51a93950d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
 * Copyright 2011-2013 Maarten Lankhorst, Ilia Mirkin
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * 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 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 "nv50/nv98_video.h"

static void
nv98_decoder_setup_ppp(struct nouveau_vp3_decoder *dec, struct nouveau_vp3_video_buffer *target, uint32_t low700) {
   struct nouveau_pushbuf *push = dec->pushbuf[2];

   uint32_t stride_in = mb(dec->base.width);
   uint32_t stride_out = mb(target->resources[0]->width0);
   uint32_t dec_h = mb(dec->base.height);
   uint32_t dec_w = mb(dec->base.width);
   uint64_t in_addr;
   uint32_t y2, cbcr, cbcr2, i;
   struct nouveau_pushbuf_refn bo_refs[] = {
      { NULL, NOUVEAU_BO_WR | NOUVEAU_BO_VRAM },
      { NULL, NOUVEAU_BO_WR | NOUVEAU_BO_VRAM },
      { dec->ref_bo, NOUVEAU_BO_RD | NOUVEAU_BO_VRAM },
#if NOUVEAU_VP3_DEBUG_FENCE
      { dec->fence_bo, NOUVEAU_BO_WR | NOUVEAU_BO_GART },
#endif
   };
   unsigned num_refs = sizeof(bo_refs)/sizeof(*bo_refs);

   for (i = 0; i < 2; ++i) {
      struct nv50_miptree *mt = (struct nv50_miptree *)target->resources[i];
      bo_refs[i].bo = mt->base.bo;
   }

   nouveau_pushbuf_refn(push, bo_refs, num_refs);
   nouveau_vp3_ycbcr_offsets(dec, &y2, &cbcr, &cbcr2);

   BEGIN_NV04(push, SUBC_PPP(0x700), 10);
   in_addr = nouveau_vp3_video_addr(dec, target) >> 8;

   PUSH_DATA (push, (stride_out << 24) | (stride_out << 16) | low700); // 700
   PUSH_DATA (push, (stride_in << 24) | (stride_in << 16) | (dec_h << 8) | dec_w); // 704
   assert(dec_w == stride_in);

   /* Input: */
   PUSH_DATA (push, in_addr); // 708
   PUSH_DATA (push, in_addr + y2); // 70c
   PUSH_DATA (push, in_addr + cbcr); // 710
   PUSH_DATA (push, in_addr + cbcr2); // 714

   for (i = 0; i < 2; ++i) {
      struct nv50_miptree *mt = (struct nv50_miptree *)target->resources[i];

      PUSH_DATA (push, mt->base.address >> 8);
      PUSH_DATA (push, (mt->base.address + mt->total_size/2) >> 8);
      mt->base.status |= NOUVEAU_BUFFER_STATUS_GPU_WRITING;
   }
}

static uint32_t
nv98_decoder_vc1_ppp(struct nouveau_vp3_decoder *dec, struct pipe_vc1_picture_desc *desc, struct nouveau_vp3_video_buffer *target) {
   struct nouveau_pushbuf *push = dec->pushbuf[2];

   nv98_decoder_setup_ppp(dec, target, 0x1412);
   assert(!desc->deblockEnable);
   assert(!(dec->base.width & 0xf));
   assert(!(dec->base.height & 0xf));

   BEGIN_NV04(push, SUBC_PPP(0x400), 1);
   PUSH_DATA (push, desc->pquant << 11);

   // 728 = wtf?
   return 0x10;
}

void
nv98_decoder_ppp(struct nouveau_vp3_decoder *dec, union pipe_desc desc, struct nouveau_vp3_video_buffer *target, unsigned comm_seq) {
   enum pipe_video_format codec = u_reduce_video_profile(dec->base.profile);
   struct nouveau_pushbuf *push = dec->pushbuf[2];
   unsigned ppp_caps = 0x10;
   unsigned fence_extra = 0;

#if NOUVEAU_VP3_DEBUG_FENCE
   fence_extra = 4;
#endif

   nouveau_pushbuf_space(push, 11 + (codec == PIPE_VIDEO_FORMAT_VC1 ? 2 : 0) + 3 + fence_extra + 2, 4, 0);

   switch (codec) {
   case PIPE_VIDEO_FORMAT_MPEG12: {
      unsigned mpeg2 = dec->base.profile != PIPE_VIDEO_PROFILE_MPEG1;
      nv98_decoder_setup_ppp(dec, target, 0x1410 | mpeg2);
      break;
   }
   case PIPE_VIDEO_FORMAT_MPEG4: nv98_decoder_setup_ppp(dec, target, 0x1414); break;
   case PIPE_VIDEO_FORMAT_VC1: ppp_caps = nv98_decoder_vc1_ppp(dec, desc.vc1, target); break;
   case PIPE_VIDEO_FORMAT_MPEG4_AVC: nv98_decoder_setup_ppp(dec, target, 0x1413); break;
   default: assert(0);
   }
   BEGIN_NV04(push, SUBC_PPP(0x734), 2);
   PUSH_DATA (push, comm_seq);
   PUSH_DATA (push, ppp_caps);

#if NOUVEAU_VP3_DEBUG_FENCE
   BEGIN_NV04(push, SUBC_PPP(0x240), 3);
   PUSH_DATAh(push, (dec->fence_bo->offset + 0x20));
   PUSH_DATA (push, (dec->fence_bo->offset + 0x20));
   PUSH_DATA (push, dec->fence_seq);

   BEGIN_NV04(push, SUBC_PPP(0x300), 1);
   PUSH_DATA (push, 1);
   PUSH_KICK (push);

   {
      unsigned spin = 0;

      do {
         usleep(100);
         if ((spin++ & 0xff) == 0xff)
            debug_printf("p%u: %u\n", dec->fence_seq, dec->fence_map[8]);
      } while (dec->fence_seq > dec->fence_map[8]);
   }
#else
   BEGIN_NV04(push, SUBC_PPP(0x300), 1);
   PUSH_DATA (push, 0);
   PUSH_KICK (push);
#endif
}