radeonsi/gfx9: update HTILE/CMASK/FMASK allocators
[mesa.git] / src / gallium / drivers / radeon / radeon_uvd.c
index 52658fa23939620b6309f3434fbe5195ddf0d987..c1746f8325fb55a80897f62587d5c1af6888ef39 100644 (file)
@@ -59,6 +59,7 @@
 #define FB_BUFFER_SIZE 2048
 #define FB_BUFFER_SIZE_TONGA (2048 * 64)
 #define IT_SCALING_TABLE_SIZE 992
+#define UVD_SESSION_CONTEXT_SIZE (128 * 1024)
 
 /* UVD decoder representation */
 struct ruvd_decoder {
@@ -89,12 +90,13 @@ struct ruvd_decoder {
        struct rvid_buffer              dpb;
        bool                            use_legacy;
        struct rvid_buffer              ctx;
+       struct rvid_buffer              sessionctx;
 };
 
 /* flush IB to the hardware */
-static void flush(struct ruvd_decoder *dec)
+static int flush(struct ruvd_decoder *dec, unsigned flags)
 {
-       dec->ws->cs_flush(dec->cs, RADEON_FLUSH_ASYNC, NULL);
+       return dec->ws->cs_flush(dec->cs, flags, NULL);
 }
 
 /* add a new set register command to the IB */
@@ -111,7 +113,8 @@ static void send_cmd(struct ruvd_decoder *dec, unsigned cmd,
 {
        int reloc_idx;
 
-       reloc_idx = dec->ws->cs_add_buffer(dec->cs, buf, usage, domain,
+       reloc_idx = dec->ws->cs_add_buffer(dec->cs, buf, usage | RADEON_USAGE_SYNCHRONIZED,
+                                          domain,
                                          RADEON_PRIO_UVD);
        if (!dec->use_legacy) {
                uint64_t addr;
@@ -120,6 +123,7 @@ static void send_cmd(struct ruvd_decoder *dec, unsigned cmd,
                set_reg(dec, RUVD_GPCOM_VCPU_DATA0, addr);
                set_reg(dec, RUVD_GPCOM_VCPU_DATA1, addr >> 32);
        } else {
+               off += dec->ws->buffer_get_reloc_offset(buf);
                set_reg(dec, RUVD_GPCOM_VCPU_DATA0, off);
                set_reg(dec, RUVD_GPCOM_VCPU_DATA1, reloc_idx * 4);
        }
@@ -170,6 +174,12 @@ static void send_msg_buf(struct ruvd_decoder *dec)
        dec->fb = NULL;
        dec->it = NULL;
 
+
+       if (dec->sessionctx.res)
+               send_cmd(dec, RUVD_CMD_SESSION_CONTEXT_BUFFER,
+                        dec->sessionctx.res->buf, 0, RADEON_USAGE_READWRITE,
+                        RADEON_DOMAIN_VRAM);
+
        /* and send it to the hardware */
        send_cmd(dec, RUVD_CMD_MSG_BUFFER, buf->res->buf, 0,
                 RADEON_USAGE_READ, RADEON_DOMAIN_GTT);
@@ -468,6 +478,7 @@ static struct ruvd_h264 get_h264_msg(struct ruvd_decoder *dec, struct pipe_h264_
        memset(&result, 0, sizeof(result));
        switch (pic->base.profile) {
        case PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE:
+       case PIPE_VIDEO_PROFILE_MPEG4_AVC_CONSTRAINED_BASELINE:
                result.profile = RUVD_H264_PROFILE_BASELINE;
                break;
 
@@ -693,13 +704,16 @@ static struct ruvd_h265 get_h265_msg(struct ruvd_decoder *dec, struct pipe_video
                        result.direct_reflist[i][j] = pic->RefPicList[i][j];
        }
 
-       if ((pic->base.profile == PIPE_VIDEO_PROFILE_HEVC_MAIN_10) &&
-               (target->buffer_format == PIPE_FORMAT_NV12)) {
-               result.p010_mode = 0;
-               result.luma_10to8 = 5;
-               result.chroma_10to8 = 5;
-               result.sclr_luma10to8 = 4;
-               result.sclr_chroma10to8 = 4;
+       if (pic->base.profile == PIPE_VIDEO_PROFILE_HEVC_MAIN_10) {
+               if (target->buffer_format == PIPE_FORMAT_P016) {
+                       result.p010_mode = 1;
+                       result.msb_mode = 1;
+               } else {
+                       result.luma_10to8 = 5;
+                       result.chroma_10to8 = 5;
+                       result.sclr_luma10to8 = 4;
+                       result.sclr_chroma10to8 = 4;
+               }
        }
 
        /* TODO
@@ -927,7 +941,7 @@ static void ruvd_destroy(struct pipe_video_codec *decoder)
        dec->msg->stream_handle = dec->stream_handle;
        send_msg_buf(dec);
 
-       flush(dec);
+       flush(dec, 0);
 
        dec->ws->cs_destroy(dec->cs);
 
@@ -937,10 +951,8 @@ static void ruvd_destroy(struct pipe_video_codec *decoder)
        }
 
        rvid_destroy_buffer(&dec->dpb);
-       if ((u_reduce_video_profile(dec->base.profile) == PIPE_VIDEO_FORMAT_HEVC) ||
-           (dec->stream_type == RUVD_CODEC_H264_PERF &&
-           ((struct r600_common_screen*)dec->screen)->family >= CHIP_POLARIS10))
-               rvid_destroy_buffer(&dec->ctx);
+       rvid_destroy_buffer(&dec->ctx);
+       rvid_destroy_buffer(&dec->sessionctx);
 
        FREE(dec);
 }
@@ -1126,12 +1138,9 @@ static void ruvd_end_frame(struct pipe_video_codec *decoder,
 
        send_cmd(dec, RUVD_CMD_DPB_BUFFER, dec->dpb.res->buf, 0,
                 RADEON_USAGE_READWRITE, RADEON_DOMAIN_VRAM);
-       if ((u_reduce_video_profile(picture->profile) == PIPE_VIDEO_FORMAT_HEVC) ||
-           (dec->stream_type == RUVD_CODEC_H264_PERF &&
-           ((struct r600_common_screen*)dec->screen)->family >= CHIP_POLARIS10)) {
+       if (dec->ctx.res)
                send_cmd(dec, RUVD_CMD_CONTEXT_BUFFER, dec->ctx.res->buf, 0,
                        RADEON_USAGE_READWRITE, RADEON_DOMAIN_VRAM);
-       }
        send_cmd(dec, RUVD_CMD_BITSTREAM_BUFFER, bs_buf->res->buf,
                 0, RADEON_USAGE_READ, RADEON_DOMAIN_GTT);
        send_cmd(dec, RUVD_CMD_DECODING_TARGET_BUFFER, dt, 0,
@@ -1143,7 +1152,7 @@ static void ruvd_end_frame(struct pipe_video_codec *decoder,
                         FB_BUFFER_OFFSET + dec->fb_size, RADEON_USAGE_READ, RADEON_DOMAIN_GTT);
        set_reg(dec, RUVD_ENGINE_CNTL, 1);
 
-       flush(dec);
+       flush(dec, RADEON_FLUSH_ASYNC);
        next_buffer(dec);
 }
 
@@ -1168,7 +1177,7 @@ struct pipe_video_codec *ruvd_create_decoder(struct pipe_context *context,
        unsigned bs_buf_size;
        struct radeon_info info;
        struct ruvd_decoder *dec;
-       int i;
+       int r, i;
 
        ws->query_info(ws, &info);
 
@@ -1265,6 +1274,16 @@ struct pipe_video_codec *ruvd_create_decoder(struct pipe_context *context,
                rvid_clear_buffer(context, &dec->ctx);
        }
 
+       if (info.family >= CHIP_POLARIS10 && info.drm_minor >= 3) {
+               if (!rvid_create_buffer(dec->screen, &dec->sessionctx,
+                                       UVD_SESSION_CONTEXT_SIZE,
+                                       PIPE_USAGE_DEFAULT)) {
+                       RVID_ERR("Can't allocated session ctx.\n");
+                       goto error;
+               }
+               rvid_clear_buffer(context, &dec->sessionctx);
+       }
+
        map_msg_fb_it_buf(dec);
        dec->msg->size = sizeof(*dec->msg);
        dec->msg->msg_type = RUVD_MSG_CREATE;
@@ -1274,7 +1293,10 @@ struct pipe_video_codec *ruvd_create_decoder(struct pipe_context *context,
        dec->msg->body.create.height_in_samples = dec->base.height;
        dec->msg->body.create.dpb_size = dpb_size;
        send_msg_buf(dec);
-       flush(dec);
+       r = flush(dec, 0);
+       if (r)
+               goto error;
+
        next_buffer(dec);
 
        return &dec->base;
@@ -1288,8 +1310,8 @@ error:
        }
 
        rvid_destroy_buffer(&dec->dpb);
-       if (dec->stream_type == RUVD_CODEC_H264_PERF && info.family >= CHIP_POLARIS10)
-               rvid_destroy_buffer(&dec->ctx);
+       rvid_destroy_buffer(&dec->ctx);
+       rvid_destroy_buffer(&dec->sessionctx);
 
        FREE(dec);
 
@@ -1299,8 +1321,8 @@ error:
 /* calculate top/bottom offset */
 static unsigned texture_offset(struct radeon_surf *surface, unsigned layer)
 {
-       return surface->level[0].offset +
-               layer * surface->level[0].slice_size;
+       return surface->u.legacy.level[0].offset +
+               layer * surface->u.legacy.level[0].slice_size;
 }
 
 /* hw encode the aspect of macro tiles */
@@ -1335,8 +1357,8 @@ static unsigned bank_wh(unsigned bankwh)
 void ruvd_set_dt_surfaces(struct ruvd_msg *msg, struct radeon_surf *luma,
                          struct radeon_surf *chroma)
 {
-       msg->body.decode.dt_pitch = luma->level[0].pitch_bytes;
-       switch (luma->level[0].mode) {
+       msg->body.decode.dt_pitch = luma->u.legacy.level[0].nblk_x;
+       switch (luma->u.legacy.level[0].mode) {
        case RADEON_SURF_MODE_LINEAR_ALIGNED:
                msg->body.decode.dt_tiling_mode = RUVD_TILE_LINEAR;
                msg->body.decode.dt_array_mode = RUVD_ARRAY_MODE_LINEAR;
@@ -1364,11 +1386,11 @@ void ruvd_set_dt_surfaces(struct ruvd_msg *msg, struct radeon_surf *luma,
                msg->body.decode.dt_chroma_bottom_offset = msg->body.decode.dt_chroma_top_offset;
        }
 
-       assert(luma->bankw == chroma->bankw);
-       assert(luma->bankh == chroma->bankh);
-       assert(luma->mtilea == chroma->mtilea);
+       assert(luma->u.legacy.bankw == chroma->u.legacy.bankw);
+       assert(luma->u.legacy.bankh == chroma->u.legacy.bankh);
+       assert(luma->u.legacy.mtilea == chroma->u.legacy.mtilea);
 
-       msg->body.decode.dt_surf_tile_config |= RUVD_BANK_WIDTH(bank_wh(luma->bankw));
-       msg->body.decode.dt_surf_tile_config |= RUVD_BANK_HEIGHT(bank_wh(luma->bankh));
-       msg->body.decode.dt_surf_tile_config |= RUVD_MACRO_TILE_ASPECT_RATIO(macro_tile_aspect(luma->mtilea));
+       msg->body.decode.dt_surf_tile_config |= RUVD_BANK_WIDTH(bank_wh(luma->u.legacy.bankw));
+       msg->body.decode.dt_surf_tile_config |= RUVD_BANK_HEIGHT(bank_wh(luma->u.legacy.bankh));
+       msg->body.decode.dt_surf_tile_config |= RUVD_MACRO_TILE_ASPECT_RATIO(macro_tile_aspect(luma->u.legacy.mtilea));
 }