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 fac03359a0f3292a916195046ba29ec861f9f3df..b23827d300a6ed0d96ffc813285ddbf67d14591c 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 0e9280dbfa20bb84e7ea68837974d77ac21d1c12..fed529c9bc7a34410570f6915c804f84c87aa90c 100644 (file)
 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
  */
index 32f038dae612dac8de08a8d1fa517a37c2f95614..620c030e11286e9c94b015671ac0f4532b49493e 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 0e8f96772c696ad42ce1fc3fef191cb0d6d38ccb..3b77c9600c6066e6a9a7204dd8b2d50b93e3d12e 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 13d25ba7dba9b2b78a232f7185487fbdf899fda3..8c0500c7dfd63ac9172318e3a8fe7ccc07cfc9e5 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 d180e36aa162ee93fd759dcde59f2413ed282b83..ceaebbb443185882df0fcc7155f3a0f850d70205 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 1e58d27be88ac4fb24d4d19d7c7878bf67ec3216..960ab8c96aed5841ef587796ed7e94b9e4c76733 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 13786067d53534208a4d488723490cec4fcb9ac1..ea25a25883db4dfa44b9a5936cddaee5caab051b 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 3bf05bea21fe06f333bef294e1e2f58da92cecce..3527f733809ffc75ad9cf06badfaf811b7add011 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 5c68cd7c47a7b4adbdf626e01cb56b30bbeac9e8..5482eff0630fbc99896252c36354f848048f9a10 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;