g3dvl: Rework the decoder interface part 2/5
authorChristian König <deathsimple@vodafone.de>
Tue, 9 Aug 2011 17:27:57 +0000 (19:27 +0200)
committerChristian König <deathsimple@vodafone.de>
Fri, 26 Aug 2011 10:10:34 +0000 (12:10 +0200)
Implement PIPE_CAP_NUM_BUFFERS_DESIRED giving the decoder control over
the number of buffers a state tracker should allocate.

Signed-off-by: Christian König <deathsimple@vodafone.de>
Reviewed-by: Younes Manton <younes.m@gmail.com>
src/gallium/auxiliary/vl/vl_decoder.c
src/gallium/auxiliary/vl/vl_decoder.h
src/gallium/drivers/nouveau/nouveau_video.c
src/gallium/drivers/nvfx/nvfx_screen.c
src/gallium/drivers/r300/r300_screen.c
src/gallium/drivers/r600/r600_pipe.c
src/gallium/drivers/softpipe/sp_screen.c
src/gallium/include/pipe/p_video_enums.h
src/gallium/state_trackers/vdpau/decode.c
src/gallium/state_trackers/vdpau/vdpau_private.h

index fac0335..b23827d 100644 (file)
@@ -44,6 +44,19 @@ vl_profile_supported(struct pipe_screen *screen, enum pipe_video_profile profile
    }
 }
 
+unsigned
+vl_num_buffers_desired(struct pipe_screen *screen, enum pipe_video_profile profile)
+{
+   assert(screen);
+   switch (u_reduce_video_profile(profile)) {
+      case PIPE_VIDEO_CODEC_MPEG12:
+         return 4;
+
+      default:
+         return 1;
+   }
+}
+
 struct pipe_video_decoder *
 vl_create_decoder(struct pipe_context *pipe,
                   enum pipe_video_profile profile,
index 0e9280d..fed529c 100644 (file)
@@ -38,6 +38,12 @@ bool
 vl_profile_supported(struct pipe_screen *screen, enum pipe_video_profile profile);
 
 /**
+ * the desired number of buffers for optimal operation
+ */
+unsigned
+vl_num_buffers_desired(struct pipe_screen *screen, enum pipe_video_profile profile);
+
+/**
  * standard implementation of pipe->create_video_decoder
  */
 struct pipe_video_decoder *
index 32f038d..620c030 100644 (file)
@@ -18,6 +18,8 @@ nouveau_screen_get_video_param(struct pipe_screen *pscreen,
    case PIPE_VIDEO_CAP_MAX_WIDTH:
    case PIPE_VIDEO_CAP_MAX_HEIGHT:
       return vl_video_buffer_max_size(pscreen);
+   case PIPE_VIDEO_CAP_NUM_BUFFERS_DESIRED:
+      return vl_num_buffers_desired(pscreen, profile);
    default:
       debug_printf("unknown video param: %d\n", param);
       return 0;
index 0e8f967..3b77c96 100644 (file)
@@ -226,6 +226,8 @@ nvfx_screen_get_video_param(struct pipe_screen *screen,
        case PIPE_VIDEO_CAP_MAX_WIDTH:
        case PIPE_VIDEO_CAP_MAX_HEIGHT:
                return vl_video_buffer_max_size(screen);
+       case PIPE_VIDEO_CAP_NUM_BUFFERS_DESIRED:
+               return vl_num_buffers_desired(screen, profile);
        default:
                return 0;
        }
index 13d25ba..8c0500c 100644 (file)
@@ -313,6 +313,8 @@ static int r300_get_video_param(struct pipe_screen *screen,
       case PIPE_VIDEO_CAP_MAX_WIDTH:
       case PIPE_VIDEO_CAP_MAX_HEIGHT:
          return vl_video_buffer_max_size(screen);
+      case PIPE_VIDEO_CAP_NUM_BUFFERS_DESIRED:
+         return vl_num_buffers_desired(screen, profile);
       default:
          return 0;
    }
index d180e36..ceaebbb 100644 (file)
@@ -505,6 +505,8 @@ static int r600_get_video_param(struct pipe_screen *screen,
        case PIPE_VIDEO_CAP_MAX_WIDTH:
        case PIPE_VIDEO_CAP_MAX_HEIGHT:
                return vl_video_buffer_max_size(screen);
+       case PIPE_VIDEO_CAP_NUM_BUFFERS_DESIRED:
+               return vl_num_buffers_desired(screen, profile);
        default:
                return 0;
        }
index 1e58d27..960ab8c 100644 (file)
@@ -185,6 +185,8 @@ softpipe_get_video_param(struct pipe_screen *screen,
    case PIPE_VIDEO_CAP_MAX_WIDTH:
    case PIPE_VIDEO_CAP_MAX_HEIGHT:
       return vl_video_buffer_max_size(screen);
+   case PIPE_VIDEO_CAP_NUM_BUFFERS_DESIRED:
+      return vl_num_buffers_desired(screen, profile);
    default:
       return 0;
    }
index 1378606..ea25a25 100644 (file)
@@ -50,7 +50,8 @@ enum pipe_video_cap
    PIPE_VIDEO_CAP_SUPPORTED = 0,
    PIPE_VIDEO_CAP_NPOT_TEXTURES = 1,
    PIPE_VIDEO_CAP_MAX_WIDTH = 2,
-   PIPE_VIDEO_CAP_MAX_HEIGHT = 3
+   PIPE_VIDEO_CAP_MAX_HEIGHT = 3,
+   PIPE_VIDEO_CAP_NUM_BUFFERS_DESIRED = 4
 };
 
 enum pipe_video_codec
index 3bf05be..3527f73 100644 (file)
@@ -82,13 +82,22 @@ vlVdpDecoderCreate(VdpDevice device,
       goto error_decoder;
    }
 
+   vldecoder->num_buffers = pipe->screen->get_video_param
+   (
+      pipe->screen, p_profile,
+      PIPE_VIDEO_CAP_NUM_BUFFERS_DESIRED
+   );
    vldecoder->cur_buffer = 0;
 
-   for (i = 0; i < VL_NUM_DECODE_BUFFERS; ++i) {
-      vldecoder->buffer[i] = vldecoder->decoder->create_buffer(vldecoder->decoder);
-      if (!vldecoder->buffer[i]) {
+   vldecoder->buffers = CALLOC(vldecoder->num_buffers, sizeof(void*));
+   if (!vldecoder->buffers)
+         goto error_alloc_buffers;
+
+   for (i = 0; i < vldecoder->num_buffers; ++i) {
+      vldecoder->buffers[i] = vldecoder->decoder->create_buffer(vldecoder->decoder);
+      if (!vldecoder->buffers[i]) {
          ret = VDP_STATUS_ERROR;
-         goto error_buffer;
+         goto error_create_buffers;
       }
    }
 
@@ -103,11 +112,15 @@ vlVdpDecoderCreate(VdpDevice device,
    return VDP_STATUS_OK;
 
 error_handle:
-error_buffer:
+error_create_buffers:
 
-   for (i = 0; i < VL_NUM_DECODE_BUFFERS; ++i)
-      if (vldecoder->buffer[i])
-         vldecoder->decoder->destroy_buffer(vldecoder->decoder, vldecoder->buffer[i]);
+   for (i = 0; i < vldecoder->num_buffers; ++i)
+      if (vldecoder->buffers[i])
+         vldecoder->decoder->destroy_buffer(vldecoder->decoder, vldecoder->buffers[i]);
+
+   FREE(vldecoder->buffers);
+
+error_alloc_buffers:
 
    vldecoder->decoder->destroy(vldecoder->decoder);
 
@@ -128,9 +141,11 @@ vlVdpDecoderDestroy(VdpDecoder decoder)
    if (!vldecoder)
       return VDP_STATUS_INVALID_HANDLE;
 
-   for (i = 0; i < VL_NUM_DECODE_BUFFERS; ++i)
-      if (vldecoder->buffer[i])
-         vldecoder->decoder->destroy_buffer(vldecoder->decoder, vldecoder->buffer[i]);
+   for (i = 0; i < vldecoder->num_buffers; ++i)
+      if (vldecoder->buffers[i])
+         vldecoder->decoder->destroy_buffer(vldecoder->decoder, vldecoder->buffers[i]);
+
+   FREE(vldecoder->buffers);
 
    vldecoder->decoder->destroy(vldecoder->decoder);
 
@@ -260,9 +275,9 @@ vlVdpDecoderRender(VdpDecoder decoder,
    case PIPE_VIDEO_PROFILE_MPEG2_SIMPLE:
    case PIPE_VIDEO_PROFILE_MPEG2_MAIN:
       ++vldecoder->cur_buffer;
-      vldecoder->cur_buffer %= VL_NUM_DECODE_BUFFERS;
+      vldecoder->cur_buffer %= vldecoder->num_buffers;
 
-      vldecoder->decoder->set_decode_buffer(vldecoder->decoder, vldecoder->buffer[vldecoder->cur_buffer]);
+      vldecoder->decoder->set_decode_buffer(vldecoder->decoder, vldecoder->buffers[vldecoder->cur_buffer]);
       vldecoder->decoder->set_decode_target(vldecoder->decoder, vlsurf->video_buffer);
 
       return vlVdpDecoderRenderMpeg12(vldecoder->decoder, (VdpPictureInfoMPEG1Or2 *)picture_info,
index 5c68cd7..5482eff 100644 (file)
@@ -46,7 +46,6 @@
 #define TOSTRING(x) QUOTEME(x)
 #define INFORMATION_STRING TOSTRING(INFORMATION)
 #define VL_HANDLES
-#define VL_NUM_DECODE_BUFFERS 4
 
 static inline enum pipe_video_chroma_format
 ChromaToPipe(VdpChromaType vdpau_type)
@@ -256,7 +255,8 @@ typedef struct
 {
    vlVdpDevice *device;
    struct pipe_video_decoder *decoder;
-   void *buffer[VL_NUM_DECODE_BUFFERS];
+   unsigned num_buffers;
+   void **buffers;
    unsigned cur_buffer;
 } vlVdpDecoder;