radeon: Move si_get_pic_param to radeon_vce.c
[mesa.git] / src / gallium / drivers / radeon / radeon_vce.c
index 0edbe0ffd19b11eb975ee396d48dd13050ac2892..652b4250654a3208afe50004a03ba7c2ee5205e0 100644 (file)
  *
  **************************************************************************/
 
-/*
- * Authors:
- *      Christian König <christian.koenig@amd.com>
- *
- */
-
 #include <stdio.h>
 
 #include "pipe/p_video_codec.h"
@@ -40,7 +34,7 @@
 
 #include "vl/vl_video_buffer.h"
 
-#include "r600_pipe_common.h"
+#include "radeonsi/si_pipe.h"
 #include "radeon_video.h"
 #include "radeon_vce.h"
 
 #define FW_52_8_3 ((52 << 24) | (8 << 16) | (3 << 8))
 #define FW_53 (53 << 24)
 
+/* version specific function for getting parameters */
+static void (*si_get_pic_param)(struct rvce_encoder *enc,
+                                struct pipe_h264_enc_picture_desc *pic) = NULL;
+
 /**
  * flush commands to the hardware
  */
 static void flush(struct rvce_encoder *enc)
 {
-       enc->ws->cs_flush(enc->cs, RADEON_FLUSH_ASYNC, NULL);
+       enc->ws->cs_flush(enc->cs, PIPE_FLUSH_ASYNC, NULL);
        enc->task_info_idx = 0;
        enc->bs_idx = 0;
 }
@@ -97,14 +95,14 @@ static void reset_cpb(struct rvce_encoder *enc)
 {
        unsigned i;
 
-       LIST_INITHEAD(&enc->cpb_slots);
+       list_inithead(&enc->cpb_slots);
        for (i = 0; i < enc->cpb_num; ++i) {
                struct rvce_cpb_slot *slot = &enc->cpb_array[i];
                slot->index = i;
                slot->picture_type = PIPE_H264_ENC_PICTURE_TYPE_SKIP;
                slot->frame_num = 0;
                slot->pic_order_cnt = 0;
-               LIST_ADDTAIL(&slot->list, &enc->cpb_slots);
+               list_addtail(&slot->list, &enc->cpb_slots);
        }
 }
 
@@ -131,13 +129,13 @@ static void sort_cpb(struct rvce_encoder *enc)
        }
 
        if (l1) {
-               LIST_DEL(&l1->list);
-               LIST_ADD(&l1->list, &enc->cpb_slots);
+               list_del(&l1->list);
+               list_add(&l1->list, &enc->cpb_slots);
        }
 
        if (l0) {
-               LIST_DEL(&l0->list);
-               LIST_ADD(&l0->list, &enc->cpb_slots);
+               list_del(&l0->list);
+               list_add(&l0->list, &enc->cpb_slots);
        }
 }
 
@@ -225,10 +223,10 @@ struct rvce_cpb_slot *si_l1_slot(struct rvce_encoder *enc)
 void si_vce_frame_offset(struct rvce_encoder *enc, struct rvce_cpb_slot *slot,
                         signed *luma_offset, signed *chroma_offset)
 {
-       struct r600_common_screen *rscreen = (struct r600_common_screen *)enc->screen;
+       struct si_screen *sscreen = (struct si_screen *)enc->screen;
        unsigned pitch, vpitch, fsize;
 
-       if (rscreen->chip_class < GFX9) {
+       if (sscreen->info.chip_class < GFX9) {
                pitch = align(enc->luma->u.legacy.level[0].nblk_x * enc->luma->bpe, 128);
                vpitch = align(enc->luma->u.legacy.level[0].nblk_y, 16);
        } else {
@@ -252,7 +250,6 @@ static void rvce_destroy(struct pipe_video_codec *encoder)
                si_vid_create_buffer(enc->screen, &fb, 512, PIPE_USAGE_STAGING);
                enc->fb = &fb;
                enc->session(enc);
-               enc->feedback(enc);
                enc->destroy(enc);
                flush(enc);
                si_vid_destroy_buffer(&fb);
@@ -347,8 +344,8 @@ static void rvce_end_frame(struct pipe_video_codec *encoder,
        slot->frame_num = enc->pic.frame_num;
        slot->pic_order_cnt = enc->pic.pic_order_cnt;
        if (!enc->pic.not_referenced) {
-               LIST_DEL(&slot->list);
-               LIST_ADD(&slot->list, &enc->cpb_slots);
+               list_del(&slot->list);
+               list_add(&slot->list, &enc->cpb_slots);
        }
 }
 
@@ -359,7 +356,9 @@ static void rvce_get_feedback(struct pipe_video_codec *encoder,
        struct rvid_buffer *fb = feedback;
 
        if (size) {
-               uint32_t *ptr = enc->ws->buffer_map(fb->res->buf, enc->cs, PIPE_TRANSFER_READ_WRITE);
+               uint32_t *ptr = enc->ws->buffer_map(
+                       fb->res->buf, enc->cs,
+                       PIPE_TRANSFER_READ_WRITE | RADEON_TRANSFER_TEMPORARY);
 
                if (ptr[1]) {
                        *size = ptr[4] - ptr[9];
@@ -395,18 +394,18 @@ struct pipe_video_codec *si_vce_create_encoder(struct pipe_context *context,
                                               struct radeon_winsys* ws,
                                               rvce_get_buffer get_buffer)
 {
-       struct r600_common_screen *rscreen = (struct r600_common_screen *)context->screen;
-       struct r600_common_context *rctx = (struct r600_common_context*)context;
+       struct si_screen *sscreen = (struct si_screen *)context->screen;
+       struct si_context *sctx = (struct si_context*)context;
        struct rvce_encoder *enc;
        struct pipe_video_buffer *tmp_buf, templat = {};
        struct radeon_surf *tmp_surf;
        unsigned cpb_size;
 
-       if (!rscreen->info.vce_fw_version) {
+       if (!sscreen->info.vce_fw_version) {
                RVID_ERR("Kernel doesn't supports VCE!\n");
                return NULL;
 
-       } else if (!si_vce_is_fw_version_supported(rscreen)) {
+       } else if (!si_vce_is_fw_version_supported(sscreen)) {
                RVID_ERR("Unsupported VCE fw version loaded!\n");
                return NULL;
        }
@@ -415,20 +414,21 @@ struct pipe_video_codec *si_vce_create_encoder(struct pipe_context *context,
        if (!enc)
                return NULL;
 
-       if (rscreen->info.drm_major == 3)
+       if (sscreen->info.is_amdgpu)
                enc->use_vm = true;
-       if ((rscreen->info.drm_major == 2 && rscreen->info.drm_minor >= 42) ||
-            rscreen->info.drm_major == 3)
+       if ((!sscreen->info.is_amdgpu && sscreen->info.drm_minor >= 42) ||
+            sscreen->info.is_amdgpu)
                enc->use_vui = true;
-       if (rscreen->info.family >= CHIP_TONGA &&
-           rscreen->info.family != CHIP_STONEY &&
-           rscreen->info.family != CHIP_POLARIS11 &&
-           rscreen->info.family != CHIP_POLARIS12)
+       if (sscreen->info.family >= CHIP_TONGA &&
+           sscreen->info.family != CHIP_STONEY &&
+           sscreen->info.family != CHIP_POLARIS11 &&
+           sscreen->info.family != CHIP_POLARIS12 &&
+           sscreen->info.family != CHIP_VEGAM)
                enc->dual_pipe = true;
        /* TODO enable B frame with dual instance */
-       if ((rscreen->info.family >= CHIP_TONGA) &&
+       if ((sscreen->info.family >= CHIP_TONGA) &&
                (templ->max_references == 1) &&
-               (rscreen->info.vce_harvest_config == 0))
+               (sscreen->info.vce_harvest_config == 0))
                enc->dual_inst = true;
 
        enc->base = *templ;
@@ -444,7 +444,7 @@ struct pipe_video_codec *si_vce_create_encoder(struct pipe_context *context,
 
        enc->screen = context->screen;
        enc->ws = ws;
-       enc->cs = ws->cs_create(rctx->ctx, RING_VCE, rvce_cs_flush, enc);
+       enc->cs = ws->cs_create(sctx->ctx, RING_VCE, rvce_cs_flush, enc, false);
        if (!enc->cs) {
                RVID_ERR("Can't get command submission context.\n");
                goto error;
@@ -466,7 +466,7 @@ struct pipe_video_codec *si_vce_create_encoder(struct pipe_context *context,
 
        get_buffer(((struct vl_video_buffer *)tmp_buf)->resources[0], NULL, &tmp_surf);
 
-       cpb_size = (rscreen->chip_class < GFX9) ?
+       cpb_size = (sscreen->info.chip_class < GFX9) ?
                align(tmp_surf->u.legacy.level[0].nblk_x * tmp_surf->bpe, 128) *
                align(tmp_surf->u.legacy.level[0].nblk_y, 32) :
 
@@ -490,7 +490,7 @@ struct pipe_video_codec *si_vce_create_encoder(struct pipe_context *context,
 
        reset_cpb(enc);
 
-       switch (rscreen->info.vce_fw_version) {
+       switch (sscreen->info.vce_fw_version) {
        case FW_40_2_2:
                si_vce_40_2_2_init(enc);
                si_get_pic_param = si_vce_40_2_2_get_param;
@@ -512,7 +512,7 @@ struct pipe_video_codec *si_vce_create_encoder(struct pipe_context *context,
                break;
 
        default:
-               if ((rscreen->info.vce_fw_version & (0xff << 24)) == FW_53) {
+               if ((sscreen->info.vce_fw_version & (0xff << 24)) >= FW_53) {
                        si_vce_52_init(enc);
                        si_get_pic_param = si_vce_52_get_param;
                } else
@@ -535,9 +535,9 @@ error:
 /**
  * check if kernel has the right fw version loaded
  */
-bool si_vce_is_fw_version_supported(struct r600_common_screen *rscreen)
+bool si_vce_is_fw_version_supported(struct si_screen *sscreen)
 {
-       switch (rscreen->info.vce_fw_version) {
+       switch (sscreen->info.vce_fw_version) {
        case FW_40_2_2:
        case FW_50_0_1:
        case FW_50_1_2:
@@ -548,7 +548,7 @@ bool si_vce_is_fw_version_supported(struct r600_common_screen *rscreen)
        case FW_52_8_3:
                return true;
        default:
-               if ((rscreen->info.vce_fw_version & (0xff << 24)) == FW_53)
+               if ((sscreen->info.vce_fw_version & (0xff << 24)) >= FW_53)
                        return true;
                else
                        return false;
@@ -565,7 +565,7 @@ void si_vce_add_buffer(struct rvce_encoder *enc, struct pb_buffer *buf,
        int reloc_idx;
 
        reloc_idx = enc->ws->cs_add_buffer(enc->cs, buf, usage | RADEON_USAGE_SYNCHRONIZED,
-                                          domain, RADEON_PRIO_VCE);
+                                          domain, 0);
        if (enc->use_vm) {
                uint64_t addr;
                addr = enc->ws->buffer_get_virtual_address(buf);