iris: Make iris_has_color_unresolved more generic
[mesa.git] / src / gallium / drivers / radeon / radeon_video.c
index 14207989325c7cf67974b365e7d968f7b010e7dd..8e2b1a3c87deba435f07246eea51e17ae1f52df0 100644 (file)
  *
  **************************************************************************/
 
-/*
- * Authors:
- *      Christian König <christian.koenig@amd.com>
- *
- */
-
-#include <unistd.h>
+#include "radeon_video.h"
 
+#include "radeon_vce.h"
+#include "radeonsi/si_pipe.h"
 #include "util/u_memory.h"
 #include "util/u_video.h"
-
 #include "vl/vl_defines.h"
 #include "vl/vl_video_buffer.h"
 
-#include "radeon/drm/radeon_winsys.h"
-#include "r600_pipe_common.h"
-#include "radeon_video.h"
-#include "radeon_vce.h"
+#include <unistd.h>
 
 /* generate an stream handle */
-unsigned rvid_alloc_stream_handle()
+unsigned si_vid_alloc_stream_handle()
 {
-       static unsigned counter = 0;
-       unsigned stream_handle = 0;
-       unsigned pid = getpid();
-       int i;
+   static unsigned counter = 0;
+   unsigned stream_handle = 0;
+   unsigned pid = getpid();
+   int i;
 
-       for (i = 0; i < 32; ++i)
-               stream_handle |= ((pid >> i) & 1) << (31 - i);
+   for (i = 0; i < 32; ++i)
+      stream_handle |= ((pid >> i) & 1) << (31 - i);
 
-       stream_handle ^= ++counter;
-       return stream_handle;
+   stream_handle ^= ++counter;
+   return stream_handle;
 }
 
 /* create a buffer in the winsys */
-bool rvid_create_buffer(struct pipe_screen *screen, struct rvid_buffer *buffer,
-                       unsigned size, unsigned usage)
+bool si_vid_create_buffer(struct pipe_screen *screen, struct rvid_buffer *buffer, unsigned size,
+                          unsigned usage)
 {
-       memset(buffer, 0, sizeof(*buffer));
-       buffer->usage = usage;
-       buffer->res = (struct r600_resource *)
-               pipe_buffer_create(screen, PIPE_BIND_CUSTOM, usage, size);
+   memset(buffer, 0, sizeof(*buffer));
+   buffer->usage = usage;
 
-       return buffer->res != NULL;
+   /* Hardware buffer placement restrictions require the kernel to be
+    * able to move buffers around individually, so request a
+    * non-sub-allocated buffer.
+    */
+   buffer->res = si_resource(pipe_buffer_create(screen, PIPE_BIND_SHARED, usage, size));
+
+   return buffer->res != NULL;
 }
 
 /* destroy a buffer */
-void rvid_destroy_buffer(struct rvid_buffer *buffer)
+void si_vid_destroy_buffer(struct rvid_buffer *buffer)
 {
-       pipe_resource_reference((struct pipe_resource **)&buffer->res, NULL);
+   si_resource_reference(&buffer->res, NULL);
 }
 
 /* reallocate a buffer, preserving its content */
-bool rvid_resize_buffer(struct pipe_screen *screen, struct radeon_winsys_cs *cs,
-                       struct rvid_buffer *new_buf, unsigned new_size)
+bool si_vid_resize_buffer(struct pipe_screen *screen, struct radeon_cmdbuf *cs,
+                          struct rvid_buffer *new_buf, unsigned new_size)
 {
-       struct r600_common_screen *rscreen = (struct r600_common_screen *)screen;
-       struct radeon_winsys* ws = rscreen->ws;
-       unsigned bytes = MIN2(new_buf->res->buf->size, new_size);
-       struct rvid_buffer old_buf = *new_buf;
-       void *src = NULL, *dst = NULL;
-
-       if (!rvid_create_buffer(screen, new_buf, new_size, new_buf->usage))
-               goto error;
-
-       src = ws->buffer_map(old_buf.res->cs_buf, cs, PIPE_TRANSFER_READ);
-       if (!src)
-               goto error;
-
-       dst = ws->buffer_map(new_buf->res->cs_buf, cs, PIPE_TRANSFER_WRITE);
-       if (!dst)
-               goto error;
-
-       memcpy(dst, src, bytes);
-       if (new_size > bytes) {
-               new_size -= bytes;
-               dst += bytes;
-               memset(dst, 0, new_size);
-       }
-       ws->buffer_unmap(new_buf->res->cs_buf);
-       ws->buffer_unmap(old_buf.res->cs_buf);
-       rvid_destroy_buffer(&old_buf);
-       return true;
+   struct si_screen *sscreen = (struct si_screen *)screen;
+   struct radeon_winsys *ws = sscreen->ws;
+   unsigned bytes = MIN2(new_buf->res->buf->size, new_size);
+   struct rvid_buffer old_buf = *new_buf;
+   void *src = NULL, *dst = NULL;
+
+   if (!si_vid_create_buffer(screen, new_buf, new_size, new_buf->usage))
+      goto error;
+
+   src = ws->buffer_map(old_buf.res->buf, cs, PIPE_TRANSFER_READ | RADEON_TRANSFER_TEMPORARY);
+   if (!src)
+      goto error;
+
+   dst = ws->buffer_map(new_buf->res->buf, cs, PIPE_TRANSFER_WRITE | RADEON_TRANSFER_TEMPORARY);
+   if (!dst)
+      goto error;
+
+   memcpy(dst, src, bytes);
+   if (new_size > bytes) {
+      new_size -= bytes;
+      dst += bytes;
+      memset(dst, 0, new_size);
+   }
+   ws->buffer_unmap(new_buf->res->buf);
+   ws->buffer_unmap(old_buf.res->buf);
+   si_vid_destroy_buffer(&old_buf);
+   return true;
 
 error:
-       if (src)
-               ws->buffer_unmap(old_buf.res->cs_buf);
-       rvid_destroy_buffer(new_buf);
-       *new_buf = old_buf;
-       return false;
+   if (src)
+      ws->buffer_unmap(old_buf.res->buf);
+   si_vid_destroy_buffer(new_buf);
+   *new_buf = old_buf;
+   return false;
 }
 
 /* clear the buffer with zeros */
-void rvid_clear_buffer(struct pipe_context *context, struct rvid_buffer* buffer)
-{
-       struct r600_common_context *rctx = (struct r600_common_context*)context;
-
-       rctx->clear_buffer(context, &buffer->res->b.b, 0, buffer->res->buf->size,
-                          0, false);
-       context->flush(context, NULL, 0);
-}
-
-/**
- * join surfaces into the same buffer with identical tiling params
- * sumup their sizes and replace the backend buffers with a single bo
- */
-void rvid_join_surfaces(struct radeon_winsys* ws, unsigned bind,
-                       struct pb_buffer** buffers[VL_NUM_COMPONENTS],
-                       struct radeon_surface *surfaces[VL_NUM_COMPONENTS])
-{
-       unsigned best_tiling, best_wh, off;
-       unsigned size, alignment;
-       struct pb_buffer *pb;
-       unsigned i, j;
-
-       for (i = 0, best_tiling = 0, best_wh = ~0; i < VL_NUM_COMPONENTS; ++i) {
-               unsigned wh;
-
-               if (!surfaces[i])
-                       continue;
-
-               /* choose the smallest bank w/h for now */
-               wh = surfaces[i]->bankw * surfaces[i]->bankh;
-               if (wh < best_wh) {
-                       best_wh = wh;
-                       best_tiling = i;
-               }
-       }
-
-       for (i = 0, off = 0; i < VL_NUM_COMPONENTS; ++i) {
-               if (!surfaces[i])
-                       continue;
-
-               /* copy the tiling parameters */
-               surfaces[i]->bankw = surfaces[best_tiling]->bankw;
-               surfaces[i]->bankh = surfaces[best_tiling]->bankh;
-               surfaces[i]->mtilea = surfaces[best_tiling]->mtilea;
-               surfaces[i]->tile_split = surfaces[best_tiling]->tile_split;
-
-               /* adjust the texture layer offsets */
-               off = align(off, surfaces[i]->bo_alignment);
-               for (j = 0; j < Elements(surfaces[i]->level); ++j)
-                       surfaces[i]->level[j].offset += off;
-               off += surfaces[i]->bo_size;
-       }
-
-       for (i = 0, size = 0, alignment = 0; i < VL_NUM_COMPONENTS; ++i) {
-               if (!buffers[i] || !*buffers[i])
-                       continue;
-
-               size = align(size, (*buffers[i])->alignment);
-               size += (*buffers[i])->size;
-               alignment = MAX2(alignment, (*buffers[i])->alignment * 1);
-       }
-
-       if (!size)
-               return;
-
-       /* TODO: 2D tiling workaround */
-       alignment *= 2;
-
-       pb = ws->buffer_create(ws, size, alignment, bind, RADEON_DOMAIN_VRAM, 0);
-       if (!pb)
-               return;
-
-       for (i = 0; i < VL_NUM_COMPONENTS; ++i) {
-               if (!buffers[i] || !*buffers[i])
-                       continue;
-
-               pb_reference(buffers[i], pb);
-       }
-
-       pb_reference(&pb, NULL);
-}
-
-int rvid_get_video_param(struct pipe_screen *screen,
-                        enum pipe_video_profile profile,
-                        enum pipe_video_entrypoint entrypoint,
-                        enum pipe_video_cap param)
-{
-       struct r600_common_screen *rscreen = (struct r600_common_screen *)screen;
-
-       if (entrypoint == PIPE_VIDEO_ENTRYPOINT_ENCODE) {
-               switch (param) {
-               case PIPE_VIDEO_CAP_SUPPORTED:
-                       return u_reduce_video_profile(profile) == PIPE_VIDEO_FORMAT_MPEG4_AVC &&
-                               rvce_is_fw_version_supported(rscreen);
-               case PIPE_VIDEO_CAP_NPOT_TEXTURES:
-                       return 1;
-               case PIPE_VIDEO_CAP_MAX_WIDTH:
-                       return 2048;
-               case PIPE_VIDEO_CAP_MAX_HEIGHT:
-                       return 1152;
-               case PIPE_VIDEO_CAP_PREFERED_FORMAT:
-                       return PIPE_FORMAT_NV12;
-               case PIPE_VIDEO_CAP_PREFERS_INTERLACED:
-                       return false;
-               case PIPE_VIDEO_CAP_SUPPORTS_INTERLACED:
-                       return false;
-               case PIPE_VIDEO_CAP_SUPPORTS_PROGRESSIVE:
-                       return true;
-               default:
-                       return 0;
-               }
-       }
-
-       /* UVD 2.x limits */
-       if (rscreen->family < CHIP_PALM) {
-               enum pipe_video_format codec = u_reduce_video_profile(profile);
-               switch (param) {
-               case PIPE_VIDEO_CAP_SUPPORTED:
-                       /* no support for MPEG4 */
-                       return codec != PIPE_VIDEO_FORMAT_MPEG4 &&
-                              /* FIXME: VC-1 simple/main profile is broken */
-                              profile != PIPE_VIDEO_PROFILE_VC1_SIMPLE &&
-                              profile != PIPE_VIDEO_PROFILE_VC1_MAIN;
-               case PIPE_VIDEO_CAP_PREFERS_INTERLACED:
-               case PIPE_VIDEO_CAP_SUPPORTS_INTERLACED:
-                       /* MPEG2 only with shaders and no support for
-                          interlacing on R6xx style UVD */
-                       return codec != PIPE_VIDEO_FORMAT_MPEG12 &&
-                              rscreen->family > CHIP_RV770;
-               default:
-                       break;
-               }
-       }
-
-       switch (param) {
-       case PIPE_VIDEO_CAP_SUPPORTED:
-               switch (u_reduce_video_profile(profile)) {
-               case PIPE_VIDEO_FORMAT_MPEG12:
-               case PIPE_VIDEO_FORMAT_MPEG4:
-               case PIPE_VIDEO_FORMAT_MPEG4_AVC:
-                       return entrypoint != PIPE_VIDEO_ENTRYPOINT_ENCODE;
-               case PIPE_VIDEO_FORMAT_VC1:
-                       /* FIXME: VC-1 simple/main profile is broken */
-                       return profile == PIPE_VIDEO_PROFILE_VC1_ADVANCED &&
-                              entrypoint != PIPE_VIDEO_ENTRYPOINT_ENCODE;
-               default:
-                       return false;
-               }
-       case PIPE_VIDEO_CAP_NPOT_TEXTURES:
-               return 1;
-       case PIPE_VIDEO_CAP_MAX_WIDTH:
-               return 2048;
-       case PIPE_VIDEO_CAP_MAX_HEIGHT:
-               return 1152;
-       case PIPE_VIDEO_CAP_PREFERED_FORMAT:
-               return PIPE_FORMAT_NV12;
-       case PIPE_VIDEO_CAP_PREFERS_INTERLACED:
-               return true;
-       case PIPE_VIDEO_CAP_SUPPORTS_INTERLACED:
-               return true;
-       case PIPE_VIDEO_CAP_SUPPORTS_PROGRESSIVE:
-               return true;
-       case PIPE_VIDEO_CAP_MAX_LEVEL:
-               switch (profile) {
-               case PIPE_VIDEO_PROFILE_MPEG1:
-                       return 0;
-               case PIPE_VIDEO_PROFILE_MPEG2_SIMPLE:
-               case PIPE_VIDEO_PROFILE_MPEG2_MAIN:
-                       return 3;
-               case PIPE_VIDEO_PROFILE_MPEG4_SIMPLE:
-                       return 3;
-               case PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE:
-                       return 5;
-               case PIPE_VIDEO_PROFILE_VC1_SIMPLE:
-                       return 1;
-               case PIPE_VIDEO_PROFILE_VC1_MAIN:
-                       return 2;
-               case PIPE_VIDEO_PROFILE_VC1_ADVANCED:
-                       return 4;
-               case PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE:
-               case PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN:
-               case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH:
-                       return 41;
-               default:
-                       return 0;
-               }
-       default:
-               return 0;
-       }
-}
-
-boolean rvid_is_format_supported(struct pipe_screen *screen,
-                                enum pipe_format format,
-                                enum pipe_video_profile profile,
-                                enum pipe_video_entrypoint entrypoint)
+void si_vid_clear_buffer(struct pipe_context *context, struct rvid_buffer *buffer)
 {
-       /* we can only handle this one with UVD */
-       if (profile != PIPE_VIDEO_PROFILE_UNKNOWN)
-               return format == PIPE_FORMAT_NV12;
+   struct si_context *sctx = (struct si_context *)context;
 
-       return vl_video_buffer_is_format_supported(screen, format, profile, entrypoint);
+   si_sdma_clear_buffer(sctx, &buffer->res->b.b, 0, buffer->res->b.b.width0, 0);
+   context->flush(context, NULL, 0);
 }